PageRenderTime 74ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/Migration/DBChanges/504_to_510rc.php

https://bitbucket.org/yousef_fadila/vtiger
PHP | 1972 lines | 1538 code | 288 blank | 146 comment | 99 complexity | 14d2d7bb62a20adadf8c363e9284e7ea MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /*+********************************************************************************
  3. * The contents of this file are subject to the vtiger CRM Public License Version 1.0
  4. * ("License"); You may not use this file except in compliance with the License
  5. * The Original Code is: vtiger CRM Open Source
  6. * The Initial Developer of the Original Code is vtiger.
  7. * Portions created by vtiger are Copyright (C) vtiger.
  8. * All Rights Reserved.
  9. *********************************************************************************/
  10. //5.0.4 to 5.1.0 RC database changes
  11. //we have to use the current object (stored in PatchApply.php) to execute the queries
  12. $adb = $_SESSION['adodb_current_object'];
  13. $conn = $_SESSION['adodb_current_object'];
  14. $migrationlog->debug("\n\nDB Changes from 5.0.4 to 5.1.0 RC -------- Starts \n\n");
  15. require_once('include/events/include.inc');
  16. $em = new VTEventsManager($adb);
  17. /* For the event api */
  18. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_eventhandlers (eventhandler_id int, event_name varchar(100), handler_path varchar(400), handler_class varchar(100), cond text, is_active boolean, primary key(eventhandler_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  19. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_eventhandler_module(eventhandler_module_id int, module_name VARCHAR(100), handler_class VARCHAR(100), PRIMARY KEY(eventhandler_module_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  20. /* Added new column actions to vtiger_relatedlists which tracks the type of actions allowed for that related list */
  21. if(!in_array('actions', $adb->getColumnNames('vtiger_relatedlists'))) {
  22. ExecuteQuery("alter table vtiger_relatedlists add column actions VARCHAR(50) default ''");
  23. }
  24. $accounts_tab_id = getTabid('Accounts');
  25. $contacts_tab_id = getTabid('Contacts');
  26. $notes_tab_id = getTabid('Documents');
  27. $products_tab_id = getTabid('Products');
  28. $leads_tab_id = getTabid('Leads');
  29. $campaigns_tab_id = getTabid('Campaigns');
  30. $potentials_tab_id = getTabid('Potentials');
  31. $emails_tab_id = getTabid('Emails');
  32. $calendar_tab_id = getTabid('Calendar');
  33. $helpdesk_tab_id = getTabid('HelpDesk');
  34. $quotes_tab_id = getTabid('Quotes');
  35. $so_tab_id = getTabid('SalesOrder');
  36. $po_tab_id = getTabid('PurchaseOrder');
  37. $invoice_tab_id = getTabid('Invoice');
  38. $pb_tab_id = getTabid('PriceBooks');
  39. $vendors_tab_id = getTabid('Vendors');
  40. // Accounts related lists
  41. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add' WHERE tabid=$accounts_tab_id");
  42. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select' WHERE tabid=$accounts_tab_id AND related_tabid=$notes_tab_id");
  43. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='select' WHERE tabid=$accounts_tab_id AND related_tabid=$products_tab_id");
  44. // Leads related lists
  45. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select' WHERE tabid=$leads_tab_idAND related_tabid=$notes_tab_id");
  46. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add' WHERE tabid=$leads_tab_id AND related_tabid IN ($calendar_tab_id,$emails_tab_id)");
  47. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='select' WHERE tabid=$leads_tab_id AND related_tabid IN ($products_tab_id,$campaigns_tab_id)");
  48. // Contacts related list
  49. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add' WHERE tabid=$contacts_tab_id");
  50. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select' WHERE tabid=$contacts_tab_id AND related_tabid=$notes_tab_id");
  51. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='select' WHERE tabid=$contacts_tab_id AND related_tabid IN ($products_tab_id,$campaigns_tab_id)");
  52. // Potentials related list
  53. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add' WHERE tabid=$potentials_tab_id AND related_tabid IN ($calendar_tab_id,$quotes_tab_id,$so_tab_id)");;
  54. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select' WHERE tabid=$potentials_tab_id AND related_tabid=$notes_tab_id");
  55. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='select' WHERE tabid=$potentials_tab_id AND related_tabid IN ($products_tab_id,$contacts_tab_id)");
  56. // Products related list
  57. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add' WHERE tabid=$products_tab_id AND related_tabid IN ($helpdesk_tab_id,$quotes_tab_id,$so_tab_id,$po_tab_id,$invoice_tab_id,$pb_tab_id)");;
  58. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select' WHERE tabid=$products_tab_id AND related_tabid=$notes_tab_id");
  59. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='select' WHERE tabid=$products_tab_id AND related_tabid IN ($accounts_tab_id,$contacts_tab_id,$leads_tab_id,$potentials_tab_id)");
  60. // Emails related lists
  61. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='select,bulkmail' WHERE tabid=$emails_tab_id AND related_tabid=$contacts_tab_id");
  62. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select' WHERE tabid=$emails_tab_id AND related_tabid=$notes_tab_id");
  63. // Trouble Tickets related lists
  64. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select' WHERE tabid=$helpdesk_tab_id AND related_tabid IN ($notes_tab_id,$calendar_tab_id)");
  65. // Products related lists
  66. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='select' WHERE tabid=$pb_tab_id AND related_tabid IN ($products_tab_id)");
  67. // Vendors related lists
  68. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add' WHERE tabid=$vendors_tab_id AND related_tabid IN ($emails_tab_id,$po_tab_id)");;
  69. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select' WHERE tabid=$vendors_tab_id AND related_tabid=$products_tab_id");
  70. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='select' WHERE tabid=$vendors_tab_id AND related_tabid IN ($contacts_tab_id)");
  71. // Quotes related lists
  72. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select' WHERE tabid=$quotes_tab_id AND related_tabid IN ($notes_tab_id)");
  73. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add' WHERE tabid=$quotes_tab_id AND related_tabid IN ($calendar_tab_id)");
  74. // PO related lists
  75. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select' WHERE tabid=$po_tab_id AND related_tabid IN ($notes_tab_id)");
  76. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add' WHERE tabid=$po_tab_id AND related_tabid IN ($calendar_tab_id)");
  77. // SO related lists
  78. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select' WHERE tabid=$so_tab_id AND related_tabid IN ($notes_tab_id)");
  79. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add' WHERE tabid=$so_tab_id AND related_tabid IN ($calendar_tab_id)");
  80. // Invoices related lists
  81. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select' WHERE tabid=$invoice_tab_id AND related_tabid IN ($notes_tab_id)");
  82. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add' WHERE tabid=$invoice_tab_id AND related_tabid IN ($calendar_tab_id)");
  83. // Campaigns related lists
  84. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select' WHERE tabid=$campaigns_tab_id AND related_tabid IN ($contacts_tab_id,$leads_tab_id)");
  85. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add' WHERE tabid=$campaigns_tab_id AND related_tabid IN ($calendar_tab_id,$potentials_tab_id)");
  86. require_once("modules/com_vtiger_workflow/include.inc");
  87. require_once("modules/com_vtiger_workflow/tasks/VTEntityMethodTask.inc");
  88. require_once("modules/com_vtiger_workflow/VTEntityMethodManager.inc");
  89. $emm = new VTEntityMethodManager($adb);
  90. /* Update the profileid, block id in sequence table, to the current highest value of block id used. */
  91. $tmp = $adb->getUniqueId('vtiger_blocks');
  92. $max_block_id_query = $adb->query("SELECT MAX(blockid) AS max_blockid FROM vtiger_blocks");
  93. if($adb->num_rows($max_block_id_query)>0){
  94. $max_block_id = $adb->query_result($max_block_id_query,0,"max_blockid");
  95. ExecuteQuery("UPDATE vtiger_blocks_seq SET id=".($max_block_id));
  96. }
  97. $tmp = $adb->getUniqueId('vtiger_profile');
  98. $max_profile_id_query = $adb->query("SELECT MAX(profileid) AS max_profileid FROM vtiger_profile");
  99. if($adb->num_rows($max_profile_id_query)>0){
  100. $max_profile_id = $adb->query_result($max_profile_id_query,0,"max_profileid");
  101. ExecuteQuery("UPDATE vtiger_profile_seq SET id=".($max_profile_id));
  102. }
  103. /* Migration queries to cleanup ui type 15, 16, 111 -
  104. * 15 for Standard picklist types,
  105. * 16 for non-standard picklist types which do not support Role-based picklist */
  106. ExecuteQuery("update vtiger_field set uitype = '15' where uitype='16'");
  107. ExecuteQuery("update vtiger_field set uitype = '15', typeofdata='V~M' where uitype='111'");
  108. ExecuteQuery("update vtiger_field set uitype=16 where fieldname in " .
  109. "('visibility','duration_minutes','recurringtype','hdnTaxType','recurring_frequency','activity_view','lead_view','date_format','reminder_interval')" .
  110. " and uitype = '15'");
  111. /* Function to add Field Security for newly added fields */
  112. function addFieldSecurity($tabid, $fieldid, $allow_merge=false) {
  113. global $adb;
  114. ExecuteQuery("INSERT INTO vtiger_def_org_field (tabid, fieldid, visible, readonly) VALUES ($tabid, $fieldid, 0, 1)");
  115. $profile_result = $adb->query("select distinct(profileid) as profileid from vtiger_profile");
  116. $num_profiles = $adb->num_rows($profile_result);
  117. for($j=0; $j<$num_profiles; $j++) {
  118. $profileid = $adb->query_result($profile_result,$j,'profileid');
  119. ExecuteQuery("INSERT INTO vtiger_profile2field (profileid, tabid, fieldid, visible, readonly) VALUES($profileid, $tabid, $fieldid, 0, 1)");
  120. }
  121. }
  122. /* Add Total column in default customview of Purchase Order */
  123. $res = $adb->query("select cvid from vtiger_customview where viewname='All' and entitytype='PurchaseOrder'");
  124. if($adb->num_rows($res)>0){
  125. $po_cvid = $adb->query_result($res, 0, 'cvid');
  126. $adb->query("update vtiger_cvcolumnlist set columnindex = 5 where columnindex = 4 and cvid = $po_cvid");
  127. $adb->query("insert into vtiger_cvcolumnlist values ($po_cvid, 4, 'vtiger_purchaseorder:total:hdnGrandTotal:PurchaseOrder_Total:V')");
  128. }
  129. /* To Provide an option to Create Product from Quick Create */
  130. ExecuteQuery("UPDATE vtiger_field SET quickcreate = 0 WHERE tablename='vtiger_products' and columnname='productname'");
  131. ExecuteQuery("UPDATE vtiger_field SET quickcreate = 0 WHERE tablename='vtiger_products' and columnname='discontinued'");
  132. ExecuteQuery("UPDATE vtiger_field SET quickcreate = 0 WHERE tablename='vtiger_products' and columnname='unit_price'");
  133. ExecuteQuery("UPDATE vtiger_field SET quickcreate = 0 WHERE tablename='vtiger_products' and columnname='qtyinstock'");
  134. /* Necessary DB Changes for Restoring the Related information of a Deleted Record */
  135. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_relatedlists_rb(entityid int(19), action varchar(50), rel_table varchar(200), rel_column varchar(200), ref_column varchar(200), related_crm_ids text) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  136. // Enable Search icon for all profiles by default for Recyclebin module
  137. $profileresult = $adb->query("select * from vtiger_profile");
  138. $countprofiles = $adb->num_rows($profileresult);
  139. for($i=0;$i<$countprofiles;$i++)
  140. {
  141. $profileid = $adb->query_result($profileresult,$i,'profileid');
  142. ExecuteQuery("insert into vtiger_profile2utility values($profileid,30,3,0)");
  143. ExecuteQuery("insert into vtiger_profile2tab values ($profileid,30,0)");
  144. }
  145. /* For Role based customview support */
  146. ExecuteQuery("alter table vtiger_customview add column status int(1) default '3'");
  147. ExecuteQuery("update vtiger_customview set status=0 where viewname='All'");
  148. ExecuteQuery("alter table vtiger_customview add column userid int(19) default '1'");
  149. /* Reminder Popup support for Calendar Events */
  150. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_activity_reminder_popup(reminderid int(19) NOT NULL AUTO_INCREMENT,semodule varchar(100) NOT NULL,recordid varchar(100) NOT NULL,date_start DATE,time_start varchar(100) NOT NULL,status int(2) NOT NULL, PRIMARY KEY(reminderid)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  151. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_reminder_interval(reminder_intervalid int(19) NOT NULL AUTO_INCREMENT,reminder_interval varchar(200) NOT NULL,sortorderid int(19) NOT NULL,presence int(1) NOT NULL, PRIMARY KEY(reminder_intervalid)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  152. ExecuteQuery("alter table vtiger_users add column reminder_interval varchar(100) NOT NULL");
  153. ExecuteQuery("alter table vtiger_users add column reminder_next_time varchar(100)");
  154. ExecuteQuery("INSERT INTO vtiger_reminder_interval values(".$adb->getUniqueId("vtiger_reminder_interval").",'None',0,1)");
  155. ExecuteQuery("INSERT INTO vtiger_reminder_interval values(".$adb->getUniqueId("vtiger_reminder_interval").",'1 Minute',1,1)");
  156. ExecuteQuery("INSERT INTO vtiger_reminder_interval values(".$adb->getUniqueId("vtiger_reminder_interval").",'5 Minutes',2,1)");
  157. ExecuteQuery("INSERT INTO vtiger_reminder_interval values(".$adb->getUniqueId("vtiger_reminder_interval").",'15 Minutes',3,1)");
  158. ExecuteQuery("INSERT INTO vtiger_reminder_interval values(".$adb->getUniqueId("vtiger_reminder_interval").",'30 Minutes',4,1)");
  159. ExecuteQuery("INSERT INTO vtiger_reminder_interval values(".$adb->getUniqueId("vtiger_reminder_interval").",'45 Minutes',5,1)");
  160. ExecuteQuery("INSERT INTO vtiger_reminder_interval values(".$adb->getUniqueId("vtiger_reminder_interval").",'1 Hour',6,1)");
  161. ExecuteQuery("INSERT INTO vtiger_reminder_interval values(".$adb->getUniqueId("vtiger_reminder_interval").",'1 Day',7,1)");
  162. ExecuteQuery("UPDATE vtiger_users SET reminder_interval='5 Minutes', reminder_next_time='".date('Y-m-d H:i')."'");
  163. $user_adv_block_id = $adb->getUniqueID('vtiger_blocks');
  164. ExecuteQuery("insert into vtiger_blocks values (".$user_adv_block_id.",29,'LBL_USER_ADV_OPTIONS',5,0,0,0,0,0)"); //Added a New Block User Image Info in Users Module
  165. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values (29,".$adb->getUniqueID("vtiger_field").",'reminder_interval','vtiger_users',1,'16','reminder_interval','Reminder Interval',1,0,0,100,1,$user_adv_block_id,1,'V~O',1,null,'BAS')");
  166. /* For Duplicate Records Merging feature */
  167. ExecuteQuery("INSERT INTO vtiger_actionmapping values(10,'DuplicatesHandling',0)");
  168. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_user2mergefields (userid int(11) REFERENCES vtiger_users( id ) , tabid int( 19 ) ,fieldid int( 19 ), visible int(2)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  169. $tabid = Array();
  170. $tab_res = $adb->query("SELECT distinct tabid FROM vtiger_tab");
  171. $noOfTabs = $adb->num_rows($tab_res);
  172. for($i=0;$i<$noOfTabs;$i++) {
  173. $tabid[] = $adb->query_result($tab_res,$i,'tabid');
  174. }
  175. $profile_sql = $adb->query("select profileid from vtiger_profile");
  176. $num_profile = $adb->num_rows($profile_sql);
  177. /*Duplicate merging is supported for
  178. * Accounts, Potentials, Contacts, Leads, Products, Vendors, TroubleTickets
  179. */
  180. $dupSupported = array(6, 2, 4, 7, 14, 18, 13);
  181. for($i=0;$i<$num_profile;$i++) {
  182. $profile_id = $adb->query_result($profile_sql,$i,'profileid');
  183. for($j=0;$j<$noOfTabs;$j++) {
  184. if (in_array($tabid[$j], $dupSupported)) {
  185. ExecuteQuery("insert into vtiger_profile2utility values($profile_id,".$tabid[$j].",10,0)");
  186. }
  187. }
  188. }
  189. /* Local Backup Feature */
  190. ExecuteQuery("alter table vtiger_systems add column server_path varchar(256)");
  191. /* Multi-Currency Support in Products, Pricebooks and Other Inventory Modules */
  192. // To save mapping between products and its price in different currencies.
  193. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_productcurrencyrel (productid int(11) not null, currencyid int(11) not null, converted_price decimal(25,2) default NULL, actual_price decimal(25, 2) default NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  194. // Update Product related tables
  195. ExecuteQuery("alter table vtiger_products drop column currency");
  196. ExecuteQuery("alter table vtiger_products add column currency_id int(19) not null default '1'");
  197. // Update Currency related tables
  198. ExecuteQuery("alter table vtiger_currency_info add column deleted int(1) not null default '0'");
  199. // Update Inventory related tables
  200. ExecuteQuery("alter table vtiger_quotes drop column currency");
  201. ExecuteQuery("alter table vtiger_quotes add column currency_id int(19) not null default '1'");
  202. ExecuteQuery("alter table vtiger_quotes add column conversion_rate decimal(10,3) not null default '1.000'");
  203. $field_id = $adb->getUniqueID('vtiger_field');
  204. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values(20,$field_id,'currency_id','vtiger_quotes','1','117','currency_id','Currency','1','0','1','100','21','51','3','I~O','1',null,'BAS')");
  205. addFieldSecurity(20,$field_id);
  206. $field_id = $adb->getUniqueID('vtiger_field');
  207. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values(20,$field_id,'conversion_rate','vtiger_quotes','1','1','conversion_rate','Conversion Rate','1','0','1','100','22','51','3','N~O','1',null,'BAS')");
  208. addFieldSecurity(20,$field_id);
  209. ExecuteQuery("alter table vtiger_purchaseorder add column currency_id int(19) not null default '1'");
  210. ExecuteQuery("alter table vtiger_purchaseorder add column conversion_rate decimal(10,3) not null default '1.000'");
  211. $field_id = $adb->getUniqueID('vtiger_field');
  212. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values(21,$field_id,'currency_id','vtiger_purchaseorder','1','117','currency_id','Currency','1','0','1','100','18','57','3','I~O','1',null,'BAS')");
  213. addFieldSecurity(21,$field_id);
  214. $field_id = $adb->getUniqueID('vtiger_field');
  215. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values(21,$field_id,'conversion_rate','vtiger_purchaseorder','1','1','conversion_rate','Conversion Rate','1','0','1','100','19','57','3','N~O','1',null,'BAS')");
  216. addFieldSecurity(21,$field_id);
  217. ExecuteQuery("alter table vtiger_salesorder add column currency_id int(19) not null default '1'");
  218. ExecuteQuery("alter table vtiger_salesorder add column conversion_rate decimal(10,3) not null default '1.000'");
  219. $field_id = $adb->getUniqueID('vtiger_field');
  220. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values(22,$field_id,'currency_id','vtiger_salesorder','1','117','currency_id','Currency','1','0','1','100','19','63','3','I~O','1',null,'BAS')");
  221. addFieldSecurity(22,$field_id);
  222. $field_id = $adb->getUniqueID('vtiger_field');
  223. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values(22,$field_id,'conversion_rate','vtiger_salesorder','1','1','conversion_rate','Conversion Rate','1','0','1','100','20','63','3','N~O','1',null,'BAS')");
  224. addFieldSecurity(22,$field_id);
  225. ExecuteQuery("alter table vtiger_invoice add column currency_id int(19) not null default '1'");
  226. ExecuteQuery("alter table vtiger_invoice add column conversion_rate decimal(10,3) not null default '1.000'");
  227. $field_id = $adb->getUniqueID('vtiger_field');
  228. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values(23,$field_id,'currency_id','vtiger_invoice','1','117','currency_id','Currency','1','0','1','100','18','69','3','I~O','1',null,'BAS')");
  229. addFieldSecurity(23,$field_id);
  230. $field_id = $adb->getUniqueID('vtiger_field');
  231. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values(23,$field_id,'conversion_rate','vtiger_invoice','1','1','conversion_rate','Conversion Rate','1','0','1','100','19','69','3','N~O','1',null,'BAS')");
  232. addFieldSecurity(23,$field_id);
  233. // Update Price Book related tables
  234. ExecuteQuery("alter table vtiger_pricebook drop column description");
  235. ExecuteQuery("alter table vtiger_pricebook add column currency_id int(19) not null default '1'");
  236. ExecuteQuery("alter table vtiger_pricebookproductrel add column usedcurrency int(11) not null default '1'");
  237. $pb_currency_field_id = $adb->getUniqueID('vtiger_field');
  238. $pb_tab_id = getTabid('PriceBooks');
  239. $adb->query("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values($pb_tab_id,$pb_currency_field_id,'currency_id','vtiger_pricebook','1','117','currency_id','Currency','1','0','0','100','5','48','1','I~M','0','3','BAS')");
  240. $adb->query("insert into vtiger_cvcolumnlist values('23','2','vtiger_pricebook:currency_id:currency_id:PriceBooks_Currency:I')");
  241. addFieldSecurity($pb_tab_id,$pb_currency_field_id);
  242. /* Documents module */
  243. $documents_tab_id = getTabid('Documents');
  244. ExecuteQuery("delete from vtiger_cvcolumnlist where columnname like '%Notes_Contact_Name%'");
  245. ExecuteQuery("delete from vtiger_cvcolumnlist where columnname like '%Notes_Related_to%'");
  246. ExecuteQuery("insert into vtiger_def_org_share values (".$adb->getUniqueID('vtiger_def_org_share').",$documents_tab_id,2,0)");
  247. for($i=0;$i<4;$i++)
  248. {
  249. ExecuteQuery("insert into vtiger_org_share_action2tab values(".$i.",$documents_tab_id)");
  250. }
  251. ExecuteQuery("alter table vtiger_customview drop foreign key fk_1_vtiger_customview ");
  252. ExecuteQuery("update vtiger_customview set entitytype='Documents' where entitytype='Notes'");
  253. ExecuteQuery("update vtiger_tab set ownedby=0,name='Documents',tablabel='Documents' where tabid=$documents_tab_id");
  254. ExecuteQuery("update vtiger_entityname set modulename='Documents' where tabid=$documents_tab_id");
  255. ExecuteQuery("alter table vtiger_customview add constraint FOREIGN KEY fk_1_vtiger_customview (entitytype) REFERENCES vtiger_tab (name) ON DELETE CASCADE");
  256. ExecuteQuery("UPDATE vtiger_relatedlists SET actions='add,select', related_tabid=$documents_tab_id WHERE name='get_attachments'");
  257. ExecuteQuery("alter table vtiger_notes add(folderid int(19) DEFAULT 1,filetype varchar(50) default NULL,filelocationtype varchar(5) default NULL,filedownloadcount int(19) default NULL,filestatus int(19) default NULL,filesize int(19) NOT NULL default '0',fileversion varchar(50) default NULL)");
  258. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_attachmentsfolder ( folderid int(19) AUTO_INCREMENT NOT NULL,foldername varchar(200) NOT NULL default '', description varchar(250) default '', createdby int(19) NOT NULL, sequence int(19) default NULL, PRIMARY KEY (folderid)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  259. ExecuteQuery("insert into vtiger_attachmentsfolder values (1,'Existing Notes','Contains all Notes migrated from the earlier version',1,1)");
  260. ExecuteQuery("alter table vtiger_senotesrel drop foreign key fk_2_vtiger_senotesrel ");
  261. ExecuteQuery("UPDATE vtiger_crmentity SET setype='Documents' WHERE setype='Notes'");
  262. $attachmentidQuery = 'select vtiger_seattachmentsrel.attachmentsid as attachmentid, vtiger_seattachmentsrel.crmid as id from vtiger_seattachmentsrel INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_seattachmentsrel.crmid WHERE vtiger_crmentity.deleted = 0';
  263. $res = $adb->pquery($attachmentidQuery,array());
  264. global $default_charset;
  265. if($adb->num_rows($res)>0){
  266. for($index=0;$index<$adb->num_rows($res);$index++){
  267. $attachmentid = $adb->query_result($res,$index,'attachmentid');
  268. $crmid = $adb->query_result($res,$index,'id');
  269. if($attachmentid != ''){
  270. $attachmentInfoQuery = 'select * from vtiger_attachments where attachmentsid = ?';
  271. $attachres = $adb->pquery($attachmentInfoQuery,array($attachmentid));
  272. if($adb->num_rows($attachres)>0){
  273. $filename = $adb->query_result($attachres,0,'name');
  274. $filename = $adb->sql_escape_string(html_entity_decode($filename,ENT_QUOTES,$default_charset));
  275. $attch_sub = $adb->query_result($attachres,0,'subject');
  276. $description = $adb->query_result($attachres,0,'description');
  277. $filepath = $adb->query_result($attachres,0,'path');
  278. $filetype = $adb->query_result($attachres,0,'type');
  279. if(file_exists($filepath.$attachmentid."_".$filename)) {
  280. $filesize = filesize($filepath.$attachmentid."_".$filename);
  281. $filestatus = "1";
  282. } else {
  283. $filesize = "0";
  284. $filestatus = "0";
  285. }
  286. $noteid_query = $adb->pquery("SELECT notesid FROM vtiger_notes WHERE notesid = ?",array($crmid));
  287. if($adb->num_rows($noteid_query)>0) {
  288. $notesid = $adb->query_result($noteid_query,0,"notesid");
  289. ExecuteQuery("update vtiger_notes set folderid = 1,filestatus='$filestatus',filelocationtype='I',filedownloadcount=0,fileversion='',filetype='".$filetype."',filesize='".$filesize."',filename='".$filename."' where notesid = ".$notesid);
  290. } else {
  291. require_once("modules/Documents/Documents.php");
  292. $notes_obj = new Documents();
  293. if($attch_sub == '') $attch_sub = $filename;
  294. $notes_obj->column_fields['notes_title'] = decode_html($attch_sub);
  295. $notes_obj->column_fields['notecontent'] = decode_html($description);
  296. $notes_obj->column_fields['assigned_user_id'] = 1;
  297. $notes_obj->save("Documents");
  298. $notesid = $notes_obj->id;
  299. ExecuteQuery("Update vtiger_notes set folderid=1,filedownloadcount=0, filestatus='$filestatus', fileversion='', filesize = '$filesize', filetype = '$filetype' , filelocationtype = 'I', filename = '$filename' where notesid = $notesid");
  300. ExecuteQuery("INSERT INTO vtiger_senotesrel VALUES($crmid,$notesid)");
  301. ExecuteQuery("INSERT INTO vtiger_seattachmentsrel VALUES($notesid,$attachmentid)");
  302. }
  303. }
  304. }
  305. else{
  306. ExecuteQuery("update vtiger_notes set folderid=1, filestatus=1,filelocationtype='',filedownloadcount='',fileversion='',filetype='',filesize='',filename='' where notesid = ".$notesid);
  307. }
  308. }
  309. }
  310. $fieldid = Array();
  311. for($i=0;$i<8;$i++)
  312. {
  313. $fieldid[$i] = $adb->getUniqueID("vtiger_field");
  314. }
  315. $file_block_id = $adb->getUniqueID('vtiger_blocks');
  316. ExecuteQuery("insert into vtiger_blocks values($file_block_id,$documents_tab_id,'LBL_FILE_INFORMATION',2,0,0,0,0,0)");
  317. $description_block_id_Query = 'select blockid from vtiger_blocks where tabid = '.$documents_tab_id.' and blocklabel = "" ';
  318. $desc_id = $adb->pquery($description_block_id_Query,array());
  319. if($adb->num_rows($desc_id)>0){
  320. $desc = $adb->query_result($desc_id,0,'blockid');
  321. $desc_update = 'update vtiger_blocks set blocklabel ="LBL_DESCRIPTION",show_title = 0,sequence = 3 where blockid = ?';
  322. $desc_block_update = $adb->pquery($desc_update,array($desc));
  323. ExecuteQuery("update vtiger_field set sequence=1,quickcreate=1,presence=2,block=$desc where tabid=$documents_tab_id and columnname='notecontent'");
  324. }
  325. ExecuteQuery("update vtiger_field set sequence=1 where tabid=$documents_tab_id and columnname='title'");
  326. ExecuteQuery("update vtiger_field set sequence=8,quickcreate=3 where tabid=$documents_tab_id and columnname='createdtime'");
  327. ExecuteQuery("update vtiger_field set sequence=9,quickcreate=3 where tabid=$documents_tab_id and columnname='modifiedtime'");
  328. ExecuteQuery("update vtiger_field set sequence = 3,quickcreate=3,block = $file_block_id,fieldlabel='File Name',displaytype = 1,uitype=28 where tabid = $documents_tab_id and columnname = 'filename'");
  329. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values ($documents_tab_id,".$fieldid[0].",'smownerid','vtiger_crmentity',1,53,'assigned_user_id','Assigned To',1,0,0,100,2,17,1,'V~M',0,3,'BAS')");
  330. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values ($documents_tab_id,".$fieldid[1].",'filetype','vtiger_notes',1,1,'filetype','File Type',1,2,0,100,5,$file_block_id,2,'V~O',3,'','BAS')");
  331. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values ($documents_tab_id,".$fieldid[2].",'filesize','vtiger_notes',1,1,'filesize','File Size',1,2,0,100,4,$file_block_id,2,'V~O',3,'','BAS')");
  332. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values ($documents_tab_id,".$fieldid[3].",'filelocationtype','vtiger_notes',1,27,'filelocationtype','Download Type',1,0,0,100,1,$file_block_id,1,'V~O',1,'','BAS')");
  333. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values ($documents_tab_id,".$fieldid[4].",'fileversion','vtiger_notes',1,1,'fileversion','Version',1,2,0,100,6,17,1,'V~O',1,'','BAS')");
  334. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values ($documents_tab_id,".$fieldid[5].",'filestatus','vtiger_notes',1,56,'filestatus','Active',1,2,0,100,2,$file_block_id,1,'V~O',1,'','BAS')");
  335. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values ($documents_tab_id,".$fieldid[6].",'filedownloadcount','vtiger_notes',1,1,'filedownloadcount','Download Count',1,2,0,100,6,$file_block_id,2,'I~O',3,'','BAS')");
  336. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values ($documents_tab_id,".$fieldid[7].",'folderid','vtiger_notes',1,26,'folderid','Folder Name',1,2,0,100,4,17,1,'V~O',2,'2','BAS')");
  337. for($i=0;$i<count($fieldid);$i++)
  338. {
  339. addFieldSecurity($documents_tab_id,$fieldid[$i]);
  340. }
  341. //Rename Attachments to Documents in relatedlist
  342. ExecuteQuery("update vtiger_relatedlists set label='Documents' where name = 'get_attachments'");
  343. $dbQuery = "select notesid,contact_id from vtiger_notes";
  344. $dbresult = $adb->query($dbQuery);
  345. $noofrecords = $adb->num_rows($dbresult);
  346. if($noofrecords > 0)
  347. {
  348. for($i=0;$i<$noofrecords;$i++)
  349. {
  350. $contactid = $adb->query_result($dbresult,$i,'contact_id');
  351. $notesid = $adb->query_result($dbresult,$i,'notesid');
  352. $dup_check = $adb->pquery("SELECT * from vtiger_senotesrel WHERE crmid = ? AND notesid = ?",array($contactid,$notesid));
  353. if($contactid != 0 && $adb->num_rows($dup_check)==0){
  354. ExecuteQuery("insert into vtiger_senotesrel values (".$contactid.",".$notesid.")");
  355. }
  356. }
  357. }
  358. ExecuteQuery("delete from vtiger_field where tabid = 8 and fieldname = 'contact_id'");
  359. ExecuteQuery("delete from vtiger_field where tabid = 8 and fieldname = 'parent_id'");
  360. ExecuteQuery("alter table vtiger_notes drop column contact_id");
  361. ExecuteQuery("update vtiger_cvcolumnlist set columnname='vtiger_notes:filename:filename:Documents_Filename:V' where cvid = 22 and columnindex = 3");
  362. custom_addCustomFilterColumn('Documents','All', 'vtiger_crmentity','smownerid','assigned_user_id','Documents_Assigned_To:V',7);
  363. ExecuteQuery("UPDATE vtiger_field SET columnname='name' WHERE fieldname='filename' AND tablename='vtiger_attachments' AND tabid=".getTabid('Emails'));
  364. //remove filename column from trouble ticket
  365. ExecuteQuery("alter table vtiger_troubletickets drop column filename");
  366. ExecuteQuery("delete from vtiger_field where fieldname='filename' and tablename='vtiger_attachments' AND tabid=".getTabid('HelpDesk'));
  367. //End: Database changes regarding Documents module
  368. /* Home Page Customization */
  369. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_homestuff (stuffid int(19) NOT NULL default '0', stuffsequence int(19) NOT NULL default '0', stufftype varchar(100) default NULL, userid int(19) NOT NULL, visible int(10) NOT NULL default '0', stufftitle varchar(100) default NULL, PRIMARY KEY (stuffid), KEY stuff_stuffid_idx (stuffid), KEY fk_1_vtiger_homestuff (userid)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  370. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_homedashbd (stuffid int(19) NOT NULL default 0, dashbdname varchar(100) default NULL, dashbdtype varchar(100) default NULL, PRIMARY KEY (stuffid), KEY stuff_stuffid_idx (stuffid)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  371. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_homedefault (stuffid int(19) NOT NULL default 0, hometype varchar(30) NOT NULL, maxentries int(19) default NULL, setype varchar(30) default NULL, PRIMARY KEY (stuffid), KEY stuff_stuffid_idx (stuffid)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  372. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_homemodule (stuffid int(19) NOT NULL, modulename varchar(100) default NULL, maxentries int(19) NOT NULL, customviewid int(19) NOT NULL, setype varchar(30) NOT NULL, PRIMARY KEY (stuffid), KEY stuff_stuffid_idx (stuffid)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  373. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_homemoduleflds (stuffid int(19) default NULL, fieldname varchar(255) default NULL, KEY stuff_stuffid_idx (stuffid)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  374. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_homerss (stuffid int(19) NOT NULL default 0, url varchar(100) default NULL, maxentries int(19) NOT NULL, PRIMARY KEY (stuffid), KEY stuff_stuffid_idx (stuffid)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  375. ExecuteQuery("ALTER TABLE vtiger_homestuff ADD CONSTRAINT fk_1_vtiger_homestuff FOREIGN KEY (userid) REFERENCES vtiger_users (id) ON DELETE CASCADE");
  376. ExecuteQuery("ALTER TABLE vtiger_homedashbd ADD CONSTRAINT fk_1_vtiger_homedashbd FOREIGN KEY (stuffid) REFERENCES vtiger_homestuff (stuffid) ON DELETE CASCADE");
  377. ExecuteQuery("ALTER TABLE vtiger_homedefault ADD CONSTRAINT fk_1_vtiger_homedefault FOREIGN KEY (stuffid) REFERENCES vtiger_homestuff (stuffid) ON DELETE CASCADE");
  378. ExecuteQuery("ALTER TABLE vtiger_homemodule ADD CONSTRAINT fk_1_vtiger_homemodule FOREIGN KEY (stuffid) REFERENCES vtiger_homestuff (stuffid) ON DELETE CASCADE");
  379. ExecuteQuery("ALTER TABLE vtiger_homemoduleflds ADD CONSTRAINT fk_1_vtiger_homemoduleflds FOREIGN KEY (stuffid) REFERENCES vtiger_homemodule (stuffid) ON DELETE CASCADE");
  380. ExecuteQuery("ALTER TABLE vtiger_homerss ADD CONSTRAINT fk_1_vtiger_homerss FOREIGN KEY (stuffid) REFERENCES vtiger_homestuff (stuffid) ON DELETE CASCADE");
  381. //to get the users lists
  382. $query = $adb->pquery('select * from vtiger_users',array());
  383. for($i=0;$i<$adb->num_rows($query);$i++)
  384. {
  385. $userid = $adb->query_result($query,$i,'id');
  386. $s1=$adb->getUniqueID("vtiger_homestuff");
  387. $sql="insert into vtiger_homestuff values(".$s1.",1,'Default',".$userid.",1,'Top Accounts')";
  388. $res=$adb->pquery($sql,array());
  389. $s2=$adb->getUniqueID("vtiger_homestuff");
  390. $sql="insert into vtiger_homestuff values(".$s2.",2,'Default',".$userid.",1,'Home Page Dashboard')";
  391. $res=$adb->pquery($sql,array());
  392. $s3=$adb->getUniqueID("vtiger_homestuff");
  393. $sql="insert into vtiger_homestuff values(".$s3.",3,'Default',".$userid.",1,'Top Potentials')";
  394. $res=$adb->pquery($sql,array());
  395. $s4=$adb->getUniqueID("vtiger_homestuff");
  396. $sql="insert into vtiger_homestuff values(".$s4.",4,'Default',".$userid.",1,'Top Quotes')";
  397. $res=$adb->pquery($sql,array());
  398. $s5=$adb->getUniqueID("vtiger_homestuff");
  399. $sql="insert into vtiger_homestuff values(".$s5.",5,'Default',".$userid.",1,'Key Metrics')";
  400. $res=$adb->pquery($sql,array());
  401. $s6=$adb->getUniqueID("vtiger_homestuff");
  402. $sql="insert into vtiger_homestuff values(".$s6.",6,'Default',".$userid.",1,'Top Trouble Tickets')";
  403. $res=$adb->pquery($sql,array());
  404. $s7=$adb->getUniqueID("vtiger_homestuff");
  405. $sql="insert into vtiger_homestuff values(".$s7.",7,'Default',".$userid.",1,'Upcoming Activities')";
  406. $res=$adb->pquery($sql,array());
  407. $s8=$adb->getUniqueID("vtiger_homestuff");
  408. $sql="insert into vtiger_homestuff values(".$s8.",8,'Default',".$userid.",1,'My Group Allocation')";
  409. $res=$adb->pquery($sql,array());
  410. $s9=$adb->getUniqueID("vtiger_homestuff");
  411. $sql="insert into vtiger_homestuff values(".$s9.",9,'Default',".$userid.",1,'Top Sales Orders')";
  412. $res=$adb->pquery($sql,array());
  413. $s10=$adb->getUniqueID("vtiger_homestuff");
  414. $sql="insert into vtiger_homestuff values(".$s10.",10,'Default',".$userid.",1,'Top Invoices')";
  415. $res=$adb->pquery($sql,array());
  416. $s11=$adb->getUniqueID("vtiger_homestuff");
  417. $sql="insert into vtiger_homestuff values(".$s11.",11,'Default',".$userid.",1,'My New Leads')";
  418. $res=$adb->pquery($sql,array());
  419. $s12=$adb->getUniqueID("vtiger_homestuff");
  420. $sql="insert into vtiger_homestuff values(".$s12.",12,'Default',".$userid.",1,'Top Purchase Orders')";
  421. $res=$adb->pquery($sql,array());
  422. $s13=$adb->getUniqueID("vtiger_homestuff");
  423. $sql="insert into vtiger_homestuff values(".$s13.",13,'Default',".$userid.",1,'Pending Activities')";
  424. $res=$adb->pquery($sql,array());
  425. $s14=$adb->getUniqueID("vtiger_homestuff");
  426. $sql="insert into vtiger_homestuff values(".$s14.",14,'Default',".$userid.",1,'My Recent FAQs')";
  427. $res=$adb->pquery($sql,array());
  428. // Non-Default Home Page widget (no entry is requried in vtiger_homedefault below)
  429. $tc = $adb->getUniqueID("vtiger_homestuff");
  430. $sql="insert into vtiger_homestuff values($tc, 15, 'Tag Cloud', $userid, 0, 'Tag Cloud')";
  431. $adb->query($sql);
  432. $sql="insert into vtiger_homedefault values(".$s1.",'ALVT',5,'Accounts')";
  433. $adb->pquery($sql,array());
  434. $sql="insert into vtiger_homedefault values(".$s2.",'HDB',5,'Dashboard')";
  435. $adb->pquery($sql,array());
  436. $sql="insert into vtiger_homedefault values(".$s3.",'PLVT',5,'Potentials')";
  437. $adb->pquery($sql,array());
  438. $sql="insert into vtiger_homedefault values(".$s4.",'QLTQ',5,'Quotes')";
  439. $adb->pquery($sql,array());
  440. $sql="insert into vtiger_homedefault values(".$s5.",'CVLVT',5,'NULL')";
  441. $adb->pquery($sql,array());
  442. $sql="insert into vtiger_homedefault values(".$s6.",'HLT',5,'HelpDesk')";
  443. $adb->pquery($sql,array());
  444. $sql="insert into vtiger_homedefault values(".$s7.",'UA',5,'Calendar')";
  445. $adb->pquery($sql,array());
  446. $sql="insert into vtiger_homedefault values(".$s8.",'GRT',5,'NULL')";
  447. $adb->pquery($sql,array());
  448. $sql="insert into vtiger_homedefault values(".$s9.",'OLTSO',5,'SalesOrder')";
  449. $adb->pquery($sql,array());
  450. $sql="insert into vtiger_homedefault values(".$s10.",'ILTI',5,'Invoice')";
  451. $adb->pquery($sql,array());
  452. $sql="insert into vtiger_homedefault values(".$s11.",'MNL',5,'Leads')";
  453. $adb->pquery($sql,array());
  454. $sql="insert into vtiger_homedefault values(".$s12.",'OLTPO',5,'PurchaseOrder')";
  455. $adb->pquery($sql,array());
  456. $sql="insert into vtiger_homedefault values(".$s13.",'PA',5,'Calendar')";
  457. $adb->pquery($sql,array());
  458. $sql="insert into vtiger_homedefault values(".$s14.",'LTFAQ',5,'Faq')";
  459. $adb->pquery($sql,array());
  460. }
  461. for($i=0;$i<$adb->num_rows($query);$i++)
  462. {
  463. $def_homeorder = $adb->query_result($query,$i,'homeorder');
  464. $user_id = $adb->query_result($query,$i,'id');
  465. $def_array = explode(",",$def_homeorder);
  466. $sql = $adb->pquery("SELECT vtiger_homestuff.stuffid FROM vtiger_homestuff INNER JOIN vtiger_homedefault WHERE vtiger_homedefault.hometype in (". generateQuestionMarks($def_array) . ") AND vtiger_homestuff.stuffid = vtiger_homedefault.stuffid AND vtiger_homestuff.userid = ?",array($def_array,$user_id));
  467. $stuffid_list = array();
  468. for($j=0;$j<$adb->num_rows($sql);$j++) {
  469. $stuffid_list[] = $adb->query_result($sql,$j,'stuffid');
  470. }
  471. $adb->pquery("UPDATE vtiger_homestuff SET visible = 0 WHERE stuffid in (". generateQuestionMarks($stuffid_list) .")",array($stuffid_list));
  472. }
  473. /* For Layout Editor */
  474. ExecuteQuery("ALTER TABLE vtiger_blocks ADD COLUMN display_status int(1) NOT NULL DEFAULT '1'");
  475. /* Adding Custom Events Migration */
  476. ExecuteQuery("UPDATE vtiger_field SET uitype=15,typeofdata='V~M' WHERE tabid=16 and columnname='activitytype'");
  477. ExecuteQuery("alter table vtiger_activitytype drop column sortorderid");
  478. ExecuteQuery("alter table vtiger_activitytype add column picklist_valueid int(19) NOT NULL default '0'");
  479. $picklist_id = $adb->getUniqueId("vtiger_picklist");
  480. ExecuteQuery("INSERT INTO vtiger_picklist VALUES(".$picklist_id.",'activitytype')");
  481. $query = $adb->pquery("SELECT * from vtiger_activitytype",array());
  482. for($i=0;$i<$adb->num_rows($query);$i++){
  483. $picklist_valueid = $adb->getUniqueID('vtiger_picklistvalues');
  484. $activitytypeid = $adb->query_result($query,$i,'activitytypeid');
  485. $adb->pquery("UPDATE vtiger_activitytype SET picklist_valueid=? , presence=0 WHERE activitytypeid = ? ",array($picklist_valueid,$activitytypeid));
  486. }
  487. $role_query = $adb->query("SELECT * FROM vtiger_role");
  488. for($j=0;$j<$adb->num_rows($role_query);$j++){
  489. $roleid = $adb->query_result($role_query,$j,'roleid');
  490. $query = $adb->pquery("SELECT * from vtiger_activitytype",array());
  491. for($i=0;$i<$adb->num_rows($query);$i++){
  492. $picklist_valueid = $adb->query_result($query,$i,'picklist_valueid');
  493. ExecuteQuery("INSERT INTO vtiger_role2picklist VALUES('".$roleid."',".$picklist_valueid.",".$picklist_id.",$i)");
  494. }
  495. }
  496. $uniqueid = $adb->getUniqueID("vtiger_relatedlists");
  497. $faqtabid = getTabid('Faq');
  498. ExecuteQuery("insert into vtiger_relatedlists values($uniqueid,$faqtabid,$documents_tab_id,'get_attachments',1,'Documents',0,'add,select')");
  499. //CustomEvents Migration Ends
  500. /* Important column renaming to support database porting */
  501. $adb->pquery("ALTER TABLE vtiger_profile2standardpermissions CHANGE Operation testoperation INTEGER", array());
  502. $adb->pquery("ALTER TABLE vtiger_profile2standardpermissions CHANGE testoperation operation INTEGER", array());
  503. $renameArray = array(
  504. "vtiger_sales_stage",
  505. "vtiger_faqcategories",
  506. "vtiger_faqstatus",
  507. "vtiger_rating",
  508. "vtiger_ticketcategories",
  509. "vtiger_ticketpriorities",
  510. "vtiger_ticketseverities",
  511. "vtiger_ticketstatus"
  512. );
  513. foreach($renameArray as $tablename) {
  514. $adb->pquery("ALTER TABLE $tablename CHANGE PRESENCE testpresence INTEGER", array());
  515. $adb->pquery("ALTER TABLE $tablename CHANGE testpresence presence INTEGER", array());
  516. }
  517. // Renaming completed
  518. /* Important database schema changes to support database porting */
  519. ExecuteQuery("alter table vtiger_attachments drop index attachments_description_type_attachmentsid_idx");
  520. ExecuteQuery("alter table vtiger_attachments modify column description TEXT");
  521. ExecuteQuery("alter table vtiger_emaildetails modify column idlists TEXT");
  522. /* Product Bundles Feature */
  523. ExecuteQuery("insert into vtiger_relatedlists values(".$adb->getUniqueID('vtiger_relatedlists').",".getTabid("Products").",".getTabid("Products").",'get_products',13,'Product Bundles',0,'add,select')");
  524. ExecuteQuery("insert into vtiger_relatedlists values(".$adb->getUniqueID('vtiger_relatedlists').",".getTabid("Products").",".getTabid("Products").",'get_parent_products',14,'Parent Products',0,'')");
  525. /* vtmailscanner customization */
  526. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_mailscanner(scannerid INT AUTO_INCREMENT NOT NULL PRIMARY KEY,scannername VARCHAR(30),
  527. server VARCHAR(100),protocol VARCHAR(10),username VARCHAR(255),password VARCHAR(255),ssltype VARCHAR(10),
  528. sslmethod VARCHAR(30),connecturl VARCHAR(255),searchfor VARCHAR(10),markas VARCHAR(10),isvalid INT(1)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  529. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_mailscanner_ids(scannerid INT, messageid TEXT,crmid INT) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  530. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_mailscanner_folders(folderid INT AUTO_INCREMENT NOT NULL PRIMARY KEY,scannerid INT,foldername VARCHAR(255),lastscan VARCHAR(30),rescan INT(1), enabled INT(1)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  531. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_mailscanner_rules(ruleid INT AUTO_INCREMENT NOT NULL PRIMARY KEY,scannerid INT,fromaddress VARCHAR(255),toaddress VARCHAR(255),subjectop VARCHAR(20),subject VARCHAR(255),bodyop VARCHAR(20),body VARCHAR(255),matchusing VARCHAR(5),sequence INT) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  532. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_mailscanner_actions(actionid INT AUTO_INCREMENT NOT NULL PRIMARY KEY,scannerid INT,actiontype VARCHAR(10),module VARCHAR(30),lookup VARCHAR(30),sequence INT) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  533. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_mailscanner_ruleactions(ruleid INT,actionid INT) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  534. // END
  535. /* Recurring Invoice Feature */
  536. $new_block_seq_no = 2;
  537. // Get all the blocks of the same module (SalesOrder), and update their sequence depending on the sequence of the new block added.
  538. $res = $adb->query("SELECT blockid FROM vtiger_blocks WHERE tabid = ". getTabid('SalesOrder') ." AND sequence >= ". $new_block_seq_no);
  539. $no_of_blocks = $adb->num_rows($res);
  540. for ($i=0; $i<$no_of_blocks;$i++) {
  541. $blockid = $adb->query_result($res, $i, 'blockid');
  542. ExecuteQuery("UPDATE vtiger_blocks SET sequence = sequence+1 WHERE blockid=$blockid");
  543. }
  544. // Add new block to show recurring invoice information at specified position (sequence of blocks)
  545. $new_block_id = $adb->getUniqueID('vtiger_blocks');
  546. ExecuteQuery("INSERT INTO vtiger_blocks VALUES (".$new_block_id.",".getTabid('SalesOrder').",'Recurring Invoice Information',$new_block_seq_no,0,0,0,0,0,1)");
  547. ExecuteQuery("ALTER TABLE vtiger_salesorder ADD COLUMN enable_recurring INT default 0");
  548. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_invoice_recurring_info(salesorderid INT, recurring_frequency VARCHAR(200), start_period DATE, end_period DATE, last_recurring_date DATE default NULL, " .
  549. " payment_duration VARCHAR(200), invoice_status VARCHAR(200)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  550. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_recurring_frequency(recurring_frequency_id INT, recurring_frequency VARCHAR(200), sortorderid INT, presence INT) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  551. // Add default values for the recurring_frequency picklist
  552. ExecuteQuery("INSERT INTO vtiger_recurring_frequency values(".$adb->getUniqueID('vtiger_recurring_frequency').",'--None--',1,1)");
  553. ExecuteQuery("INSERT INTO vtiger_recurring_frequency values(".$adb->getUniqueID('vtiger_recurring_frequency').",'Daily',2,1)");
  554. ExecuteQuery("INSERT INTO vtiger_recurring_frequency values(".$adb->getUniqueID('vtiger_recurring_frequency').",'Weekly',3,1)");
  555. ExecuteQuery("INSERT INTO vtiger_recurring_frequency values(".$adb->getUniqueID('vtiger_recurring_frequency').",'Monthly',4,1)");
  556. ExecuteQuery("INSERT INTO vtiger_recurring_frequency values(".$adb->getUniqueID('vtiger_recurring_frequency').",'Quarterly',5,1)");
  557. ExecuteQuery("INSERT INTO vtiger_recurring_frequency values(".$adb->getUniqueID('vtiger_recurring_frequency').",'Yearly',6,1)");
  558. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_payment_duration(payment_duration_id INT, payment_duration VARCHAR(200), sortorderid INT, presence INT) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  559. // Add default values for the vtiger_payment_duration picklist
  560. ExecuteQuery("INSERT INTO vtiger_payment_duration values(".$adb->getUniqueID('vtiger_payment_duration').",'Net 30 days',1,1)");
  561. ExecuteQuery("INSERT INTO vtiger_payment_duration values(".$adb->getUniqueID('vtiger_payment_duration').",'Net 45 days',2,1)");
  562. ExecuteQuery("INSERT INTO vtiger_payment_duration values(".$adb->getUniqueID('vtiger_payment_duration').",'Net 60 days',3,1)");
  563. // Add fields for the Recurring Information block
  564. $salesorder_tabid = getTabid('SalesOrder');
  565. $field_id = $adb->getUniqueID('vtiger_field');
  566. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values($salesorder_tabid,$field_id,'enable_recurring','vtiger_salesorder',1,'56','enable_recurring','Enable Recurring',1,0,0,100,1,$new_block_id,1,'C~O',3,null,'BAS')");
  567. addFieldSecurity($salesorder_tabid,$field_id);
  568. $field_id = $adb->getUniqueID('vtiger_field');
  569. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values($salesorder_tabid,$field_id,'recurring_frequency','vtiger_invoice_recurring_info',1,'16','recurring_frequency','Frequency',1,0,0,100,2,$new_block_id,1,'V~O',3,null,'BAS')");
  570. addFieldSecurity($salesorder_tabid,$field_id);
  571. $field_id = $adb->getUniqueID('vtiger_field');
  572. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values($salesorder_tabid,$field_id,'start_period','vtiger_invoice_recurring_info',1,'5','start_period','Start Period',1,0,0,100,3,$new_block_id,1,'D~O',3,null,'BAS')");
  573. addFieldSecurity($salesorder_tabid,$field_id);
  574. $field_id = $adb->getUniqueID('vtiger_field');
  575. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values($salesorder_tabid,$field_id,'end_period','vtiger_invoice_recurring_info',1,'5','end_period','End Period',1,0,0,100,4,$new_block_id,1,'D~O~OTH~G~start_period~Start Period',3,null,'BAS')");
  576. addFieldSecurity($salesorder_tabid,$field_id);
  577. $field_id = $adb->getUniqueID('vtiger_field');
  578. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values($salesorder_tabid,$field_id,'payment_duration','vtiger_invoice_recurring_info',1,'16','payment_duration','Payment Duration',1,0,0,100,5,$new_block_id,1,'V~O',3,null,'BAS')");
  579. addFieldSecurity($salesorder_tabid,$field_id);
  580. $field_id = $adb->getUniqueID('vtiger_field');
  581. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type) values($salesorder_tabid,$field_id,'invoice_status','vtiger_invoice_recurring_info',1,'15','invoicestatus','Invoice Status',1,0,0,100,6,$new_block_id,1,'V~O',3,null,'BAS')");
  582. addFieldSecurity($salesorder_tabid,$field_id);
  583. // Add new picklist value 'AutoCreated' for Invoice Status and add the same for all the existing roles.
  584. $picklistRes = $adb->query("SELECT picklistid FROM vtiger_picklist WHERE name='invoicestatus'");
  585. if($adb->num_rows($picklistRes)>0){
  586. $picklistid = $adb->query_result($picklistRes,0,'picklistid');
  587. $picklist_valueid = $adb->getUniqueID('vtiger_picklistvalues');
  588. $max_seq_id_qry = $adb->pquery("SELECT max(inovicestatusid) as maxid from vtiger_invoicestatus",array());
  589. if($adb->num_rows($max_seq_id_qry)>0) {
  590. $tmp = $adb->getUniqueID('vtiger_invoicestatus');
  591. $max_seq_id = $adb->query_result($max_seq_id_qry,0,'maxid');
  592. $adb->pquery("UPDATE vtiger_invoicestatus_seq SET id=?",array($max_seq_id));
  593. }
  594. $id = $adb->getUniqueID('vtiger_invoicestatus');
  595. ExecuteQuery("insert into vtiger_invoicestatus values($id, 'AutoCreated', 1, $picklist_valueid)");
  596. //Default entries for role2picklist relation has been inserted..
  597. $sql="select roleid from vtiger_role";
  598. $role_result = $adb->pquery($sql, array());
  599. $numrow = $adb->num_rows($role_result);
  600. for($k=0; $k < $numrow; $k ++)
  601. {
  602. $roleid = $adb->query_result($role_result,$k,'roleid');
  603. $params = array($roleid, $picklist_valueid, $picklistid, $id-1);
  604. $adb->pquery("insert into vtiger_role2picklist values(?,?,?,?)", $params);
  605. }
  606. }
  607. // Add Event handler for Recurring Invoice
  608. $em->registerHandler('vtiger.entity.aftersave', 'modules/SalesOrder/RecurringInvoiceHandler.php', 'RecurringInvoiceHandler');
  609. /* Workflow Manager - com_vtiger_workflow */
  610. ExecuteQuery("CREATE TABLE IF NOT EXISTS com_vtiger_workflows_seq (id int(11)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  611. ExecuteQuery("insert into com_vtiger_workflows_seq (id) values(1)");
  612. ExecuteQuery("CREATE TABLE IF NOT EXISTS com_vtiger_workflows (workflow_id int, module_name varchar(100), summary varchar(100), test varchar(400), task_id int(11), exec_date int, execution_condition varchar(50)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  613. ExecuteQuery('CREATE TABLE IF NOT EXISTS com_vtiger_workflow_activatedonce (entity_id int, workflow_id int) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
  614. ExecuteQuery("CREATE TABLE IF NOT EXISTS com_vtiger_workflowtasks_seq (id int(11)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  615. ExecuteQuery("insert into com_vtiger_workflowtasks_seq (id) values(1)");
  616. ExecuteQuery("CREATE TABLE IF NOT EXISTS com_vtiger_workflowtasks (task_id int, workflow_id int, summary varchar(100), task text, primary key(task_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  617. ExecuteQuery("CREATE TABLE IF NOT EXISTS com_vtiger_workflowtask_queue (task_id int, entity_id varchar(100), do_after int, primary key(task_id, entity_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  618. ExecuteQuery("CREATE TABLE IF NOT EXISTS com_vtiger_workflowtasks_entitymethod_seq (id int(11)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  619. ExecuteQuery("insert into com_vtiger_workflowtasks_entitymethod_seq (id) values(1)");
  620. ExecuteQuery("CREATE TABLE IF NOT EXISTS com_vtiger_workflowtasks_entitymethod (workflowtasks_entitymethod_id int, module_name varchar(100), method_name varchar(100), function_path varchar(400), function_name varchar(100), primary key(workflowtasks_entitymethod_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  621. ExecuteQuery("CREATE TABLE com_vtiger_workflowtemplates (
  622. template_id int(11) NOT NULL default '0',
  623. module_name varchar(100) default NULL,
  624. title varchar(400) default NULL,
  625. template text, PRIMARY KEY (template_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  626. $em->registerHandler('vtiger.entity.aftersave', 'modules/com_vtiger_workflow/VTEventHandler.inc', 'VTWorkflowEventHandler');
  627. // com_vtiger_workflow ends
  628. /* Mass Edit Feature */
  629. ExecuteQuery("ALTER TABLE vtiger_field ADD COLUMN masseditable int(11) NOT NULL DEFAULT '1'");
  630. $tab_field_array = array(
  631. 'Accounts'=>array('accountname','account_id'),
  632. 'Contacts'=>array('imagename','portal','contact_id'),
  633. 'Products'=>array('imagename','product_id'),
  634. 'Invoice'=>array('invoice_no','salesorder_id'),
  635. 'SalesOrder'=>array('quote_id','salesorder_no','enable_recurring','recurring_frequency','start_period','end_period','payment_duration','invoicestatus'),
  636. 'PurchaseOrder'=>array('purchaseorder_no'),
  637. 'Quotes'=>array('quote_no'),
  638. 'HelpDesk'=>array('filename'),
  639. );
  640. foreach($tab_field_array as $index=>$value){
  641. $tabid = getTabid($index);
  642. $adb->pquery("UPDATE vtiger_field SET masseditable=0 WHERE tabid=? AND fieldname IN (".generateQuestionMarks($value).")",array($tabid,$value));
  643. }
  644. /* Showing Emails in Vendors related list */
  645. ExecuteQuery("insert into vtiger_relatedlists values(".$adb->getUniqueID('vtiger_relatedlists').",".getTabid("Vendors").",".getTabid("Emails").",'get_emails',4,'Emails',0,'add')");
  646. /* Added for module sequence number customization */
  647. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_modentity_num (num_id int(19) NOT NULL, semodule varchar(50) NOT NULL, prefix varchar(50) NOT NULL DEFAULT '', start_id varchar(50) NOT NULL, cur_id varchar(50) NOT NULL, active int(2) NOT NULL, PRIMARY KEY(num_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  648. // Setup module sequence numbering for all modules (except Invoice).
  649. function custom_addInventoryRows($paramArray){
  650. global $adb;
  651. $fieldCreateCount = 0;
  652. for($index = 0; $index < count($paramArray); ++$index) {
  653. $criteria = $paramArray[$index];
  654. $semodule = $criteria['semodule'];
  655. $adb->pquery("INSERT into vtiger_modentity_num values(?,?,?,?,?,?)",array($adb->getUniqueId("vtiger_modentity_num"),$semodule,$criteria['prefix'],$criteria['startid'],$criteria['curid'],1));
  656. }
  657. }
  658. $modseq = array(
  659. 'Leads' =>'LEA',
  660. 'Accounts' =>'ACC',
  661. 'Campaigns' =>'CAM',
  662. 'Contacts' =>'CON',
  663. 'Potentials'=>'POT',
  664. 'HelpDesk' =>'TT',
  665. 'Quotes' =>'QUO',
  666. 'SalesOrder'=>'SO',
  667. 'PurchaseOrder'=>'PO',
  668. 'Products' =>'PRO',
  669. 'Vendors' =>'VEN',
  670. 'PriceBooks'=>'PB',
  671. 'Faq' =>'FAQ',
  672. 'Documents' =>'DOC'
  673. );
  674. foreach($modseq as $modname => $prefix) {
  675. custom_addInventoryRows(
  676. array(
  677. array('semodule'=>$modname, 'active'=>'1','prefix'=>$prefix,'startid'=>'1','curid'=>'1')
  678. )
  679. );
  680. }
  681. // Setup module sequence for Invoice
  682. @include_once('user_privileges/CustomInvoiceNo.php');
  683. // We need to move the existing information of Custom numbering to database
  684. // but in case the previous setting is not available...we are defaulting
  685. if(!isset($inv_str)) $inv_str = 'INV';
  686. if(!isset($inv_no)) $inv_no = '1';
  687. custom_addInventoryRows(
  688. array(
  689. array('semodule'=>'Invoice', 'active'=>'1','prefix'=>decode_html($inv_str),'startid'=>'1','curid'=>$inv_no)
  690. )
  691. );
  692. // Add Module Number Field to UI.
  693. $blockid = getBlockId(6,'LBL_ACCOUNT_INFORMATION');
  694. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (6,".$adb->getUniqueID("vtiger_field").",'account_no','vtiger_account',1,'4','account_no','Account No',1,0,0,100,2,$blockid,1,'V~O',1,null,'BAS',0)");
  695. ExecuteQuery("ALTER TABLE vtiger_account ADD COLUMN account_no varchar(100) not null");
  696. $blockid = getBlockId(7,'LBL_LEAD_INFORMATION');
  697. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (7,".$adb->getUniqueID("vtiger_field").",'lead_no','vtiger_leaddetails',1,'4','lead_no','Lead No',1,0,0,100,3,$blockid,1,'V~O',1,null,'BAS',0)");
  698. ExecuteQuery("ALTER TABLE vtiger_leaddetails ADD COLUMN lead_no varchar(100) not null");
  699. $blockid = getBlockId(4,'LBL_CONTACT_INFORMATION');
  700. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (4,".$adb->getUniqueID("vtiger_field").",'contact_no','vtiger_contactdetails',1,'4','contact_no','Contact Id',1,0,0,100,3,$blockid,1,'V~O',1,null,'BAS',0)");
  701. ExecuteQuery("ALTER TABLE vtiger_contactdetails ADD COLUMN contact_no varchar(100) not null");
  702. $blockid = getBlockId(2,'LBL_OPPORTUNITY_INFORMATION');
  703. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (2,".$adb->getUniqueID("vtiger_field").",'potential_no','vtiger_potential',1,'4','potential_no','Potential No',1,0,0,100,2,$blockid,1,'V~O',1,null,'BAS',0)");
  704. ExecuteQuery("ALTER TABLE vtiger_potential ADD COLUMN potential_no varchar(100) not null");
  705. $blockid = getBlockId(26,'LBL_CAMPAIGN_INFORMATION');
  706. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (26,".$adb->getUniqueID("vtiger_field").",'campaign_no','vtiger_campaign',1,'4','campaign_no','Campaign No',1,0,0,100,2,$blockid,1,'V~O',1,null,'BAS',0)");
  707. ExecuteQuery("ALTER TABLE vtiger_campaign ADD COLUMN campaign_no varchar(100) not null");
  708. $blockid = getBlockId(13,'LBL_TICKET_INFORMATION');
  709. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (13,".$adb->getUniqueID("vtiger_field").",'ticket_no','vtiger_troubletickets',1,'4','ticket_no','Ticket No',1,0,0,100,1,$blockid,1,'V~O',1,null,'BAS',0)");
  710. ExecuteQuery("ALTER TABLE vtiger_troubletickets ADD COLUMN ticket_no varchar(100) not null");
  711. $blockid = getBlockId(14,'LBL_PRODUCT_INFORMATION');
  712. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (14,".$adb->getUniqueID("vtiger_field").",'product_no','vtiger_products',1,'4','product_no','Product No',1,0,0,100,2,$blockid,1,'V~O',1,null,'BAS',0)");
  713. ExecuteQuery("ALTER TABLE vtiger_products ADD COLUMN product_no varchar(100) not null");
  714. $blockid = getBlockId(8,'LBL_NOTE_INFORMATION');
  715. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (8,".$adb->getUniqueID("vtiger_field").",'note_no','vtiger_notes',1,'4','note_no','Document No',1,0,0,100,7,$blockid,1,'V~O',1,null,'BAS',0)");
  716. ExecuteQuery("ALTER TABLE vtiger_notes ADD COLUMN note_no varchar(100) not null");
  717. $blockid = getBlockId(15,'LBL_FAQ_INFORMATION');
  718. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (15,".$adb->getUniqueID("vtiger_field").",'faq_no','vtiger_faq',1,'4','faq_no','Faq No',1,0,0,100,2,$blockid,1,'V~O',1,null,'BAS',0)");
  719. ExecuteQuery("ALTER TABLE vtiger_faq ADD COLUMN faq_no varchar(100) not null");
  720. $blockid = getBlockId(18,'LBL_VENDOR_INFORMATION');
  721. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (18,".$adb->getUniqueID("vtiger_field").",'vendor_no','vtiger_vendor',1,'4','vendor_no','Vendor No',1,0,0,100,2,$blockid,1,'V~O',1,null,'BAS',0)");
  722. ExecuteQuery("ALTER TABLE vtiger_vendor ADD COLUMN vendor_no varchar(100) not null");
  723. $blockid = getBlockId(19,'LBL_PRICEBOOK_INFORMATION');
  724. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (19,".$adb->getUniqueID("vtiger_field").",'pricebook_no','vtiger_pricebook',1,'4','pricebook_no','PriceBook No',1,0,0,100,3,$blockid,1,'V~O',1,null,'BAS',0)");
  725. ExecuteQuery("ALTER TABLE vtiger_pricebook ADD COLUMN pricebook_no varchar(100) not null");
  726. $blockid = getBlockId(22,'LBL_SO_INFORMATION');
  727. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (22,".$adb->getUniqueID("vtiger_field").",'salesorder_no','vtiger_salesorder',1,'4','salesorder_no','SalesOrder No',1,0,0,100,3,$blockid,1,'V~O',1,null,'BAS',0)");
  728. ExecuteQuery("ALTER TABLE vtiger_salesorder ADD COLUMN salesorder_no varchar(100) not null");
  729. $blockid = getBlockId(21,'LBL_PO_INFORMATION');
  730. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (21,".$adb->getUniqueID("vtiger_field").",'purchaseorder_no','vtiger_purchaseorder',1,'4','purchaseorder_no','PurchaseOrder No',1,0,0,100,2,$blockid,1,'V~O',1,null,'BAS',0)");
  731. ExecuteQuery("ALTER TABLE vtiger_purchaseorder ADD COLUMN purchaseorder_no varchar(100) not null");
  732. $blockid = getBlockId(20,'LBL_QUOTE_INFORMATION');
  733. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (20,".$adb->getUniqueID("vtiger_field").",'quote_no','vtiger_quotes',1,'4','quote_no','Quote No',1,0,0,100,3,$blockid,1,'V~O',1,null,'BAS',0)");
  734. ExecuteQuery("ALTER TABLE vtiger_quotes ADD COLUMN quote_no varchar(100) not null");
  735. $field_result = $adb->query("select tabid, fieldid from vtiger_field where uitype='4'");
  736. $num_fields = $adb->num_rows($field_result);
  737. for($i = 0; $i<$num_fields; $i++)
  738. {
  739. $tab_id = $adb->query_result($field_result,$i,'tabid');
  740. $fld_id = $adb->query_result($field_result,$i,'fieldid');
  741. addFieldSecurity($tab_id, $fld_id, false);
  742. }
  743. ExecuteQuery("update vtiger_field set uitype = '4' where tabid = 23 and columnname = 'invoice_no' ");
  744. ExecuteQuery("update vtiger_field set typeofdata = 'V~O' where tabid = 23 and columnname = 'invoice_no' ");
  745. // ADD COLUMN TO SPECIFIED MODULE CUSTOM VIEW / FILTER.
  746. function custom_addCustomFilterColumn($module, $filtername, $tablename, $columnname, $fieldname, $displayinfo, $columnindex=0) {
  747. global $adb;
  748. $result = $adb->query("SELECT * FROM vtiger_customview WHERE entitytype = '".$adb->sql_escape_string($module)."' AND viewname = '".$adb->sql_escape_string($filtername)."'");
  749. if($adb->num_rows($result) > 0) {
  750. $cvid = $adb->query_result($result, 0, 'cvid');
  751. }
  752. if($cvid == null) return;
  753. // (cvid, columnindex) is combined key so we have to update columnindex suitably
  754. ExecuteQuery("UPDATE vtiger_cvcolumnlist set columnindex=columnindex+1 WHERE cvid = $cvid AND columnindex >= $columnindex ORDER BY columnindex DESC");
  755. $cvcolumnname_value = $tablename . ":" . $columnname . ":" . $fieldname . ":" . $displayinfo;
  756. ExecuteQuery("INSERT INTO vtiger_cvcolumnlist(cvid, columnindex, columnname) VALUES ($cvid, $columnindex, '$cvcolumnname_value')");
  757. }
  758. // REMOVE SPECIFIED COLUMN FROM MODULE FILTER.
  759. function custom_removeCustomFilterColumn($module, $filtername, $tablename, $columnname, $fieldname, $displayinfo) {
  760. global $adb;
  761. $result = $adb->query("SELECT * FROM vtiger_customview WHERE entitytype = '".$adb->sql_escape_string($module)."' AND viewname = '".$adb->sql_escape_string($filtername)."'");
  762. if($adb->num_rows($result) > 0) {
  763. $cvid = $adb->query_result($result, 0, 'cvid');
  764. }
  765. if($cvid == null) return;
  766. $cvcolumnname_value = $tablename . ":" . $columnname . ":" . $fieldname . ":" . $displayinfo;
  767. ExecuteQuery("DELETE FROM vtiger_cvcolumnlist where cvid = $cvid and columnname like '$cvcolumnname_value:%' ");
  768. }
  769. custom_addCustomFilterColumn('Leads', 'All', 'vtiger_leaddetails', 'lead_no', 'lead_no', 'Leads_Lead_No:V');
  770. custom_addCustomFilterColumn('Accounts', 'All', 'vtiger_account', 'account_no', 'account_no', 'Accounts_Account_No:V');
  771. custom_addCustomFilterColumn('Campaigns', 'All', 'vtiger_campaign', 'campaign_no', 'campaign_no', 'Campaigns_Campaign_No:V');
  772. custom_addCustomFilterColumn('Contacts', 'All', 'vtiger_contactdetails', 'contact_no', 'contact_no', 'Contacts_Contact_Id:V');
  773. custom_addCustomFilterColumn('Potentials', 'All', 'vtiger_potential', 'potential_no', 'potential_no', 'Potentials_Potential_No:V');
  774. custom_removeCustomFilterColumn('HelpDesk', 'All', 'vtiger_crmentity', 'crmid', '', 'HelpDesk_Ticket_ID');
  775. custom_addCustomFilterColumn('HelpDesk', 'All', 'vtiger_troubletickets', 'ticket_no', 'ticket_no', 'HelpDesk_Ticket_No:V');
  776. custom_removeCustomFilterColumn('Quotes', 'All', 'vtiger_crmentity', 'crmid', '', 'Quotes_Quote_No');
  777. custom_addCustomFilterColumn('Quotes', 'All', 'vtiger_quotes', 'quote_no', 'quote_no', 'Quotes_Quote_No:V');
  778. custom_removeCustomFilterColumn('SalesOrder', 'All', 'vtiger_crmentity', 'crmid','','SalesOrder_Order_No');
  779. custom_addCustomFilterColumn('SalesOrder', 'All', 'vtiger_salesorder', 'salesorder_no', 'salesorder_no', 'SalesOrder_SalesOrder_No:V');
  780. custom_removeCustomFilterColumn('PurchaseOrder', 'All', 'vtiger_crmentity', 'crmid', '', 'PurchaseOrder_Order_No');
  781. custom_addCustomFilterColumn('PurchaseOrder', 'All', 'vtiger_purchaseorder', 'purchaseorder_no', 'purchaseorder_no', 'PurchaseOrder_PurchaseOrder_No:V');
  782. custom_addCustomFilterColumn('Products', 'All', 'vtiger_products', 'product_no', 'product_no', 'Products_Product_No:V');
  783. custom_addCustomFilterColumn('Vendors', 'All', 'vtiger_vendor', 'vendor_no', 'vendor_no', 'Vendors_Vendor_No:V');
  784. custom_addCustomFilterColumn('PriceBooks', 'All', 'vtiger_pricebook', 'pricebook_no', 'pricebook_no', 'PriceBooks_PriceBook_No:V');
  785. custom_removeCustomFilterColumn('Faq', 'All', 'vtiger_faq', 'id', '', 'Faq_FAQ_Id');
  786. custom_addCustomFilterColumn('Faq', 'All', 'vtiger_faq', 'faq_no', 'faq_no', 'Faq_Faq_No:V');
  787. custom_addCustomFilterColumn('Documents', 'All', 'vtiger_notes', 'note_no', 'note_no', 'Notes_Note_No:V');
  788. // Sequence number customization ends
  789. /*asterisk related changes*/
  790. $sql = "drop table if exists vtiger_asteriskextensions";
  791. ExecuteQuery($sql);
  792. $sql = "create table vtiger_asteriskextensions (userid int(11), asterisk_extension varchar(50), use_asterisk varchar(3)) ENGINE=InnoDB DEFAULT CHARSET=utf8";
  793. ExecuteQuery($sql);
  794. $sql = "drop table if exists vtiger_asterisk";
  795. ExecuteQuery($sql);
  796. $sql = "create table vtiger_asterisk (server varchar(30), port varchar(30), username varchar(50), password varchar(50), version varchar(50)) ENGINE=InnoDB DEFAULT CHARSET=utf8";
  797. ExecuteQuery($sql);
  798. $sql = "drop table if exists vtiger_asteriskincomingcalls";
  799. ExecuteQuery($sql);
  800. $sql = "create table vtiger_asteriskincomingcalls (from_number varchar(50) not null, from_name varchar(50) not null, to_number varchar(50) not null, callertype varchar(30), flag int(19), timer int(19)) ENGINE=InnoDB DEFAULT CHARSET=utf8";
  801. ExecuteQuery($sql);
  802. $sql = "drop table if exists vtiger_asteriskoutgoingcalls";
  803. ExecuteQuery($sql);
  804. $sql = "create table vtiger_asteriskoutgoingcalls (userid int(11) not null, from_number varchar(30) not null, to_number varchar(30) not null) ENGINE=InnoDB DEFAULT CHARSET=utf8";
  805. ExecuteQuery($sql);
  806. /*asterisk changes end here*/
  807. /* Updated phone field uitype */
  808. ExecuteQuery("update vtiger_field set uitype='11' where fieldname='mobile' and tabid=".getTabid('Leads'));
  809. ExecuteQuery("update vtiger_field set uitype='11' where fieldname='mobile' and tabid=".getTabid('Contacts'));
  810. ExecuteQuery("update vtiger_field set uitype='11' where fieldname='fax' and tabid=".getTabid('Leads'));
  811. ExecuteQuery("update vtiger_field set uitype='11' where fieldname='fax' and tabid=".getTabid('Contacts'));
  812. ExecuteQuery("update vtiger_field set uitype='11' where fieldname='fax' and tabid=".getTabid('Accounts'));
  813. /* Support to Configure the functionality of Updating Inventory Stock for Invoice/SalesOrder */
  814. ExecuteQuery("ALTER TABLE vtiger_inventoryproductrel ADD COLUMN incrementondel int(11) not null default '0'");
  815. $invoiceids = $adb->pquery("SELECT invoiceid from vtiger_invoice",array());
  816. $noOfRows = $adb->num_rows($invoiceids);
  817. for($i=0;$i<$noOfRows;$i++){
  818. $adb->pquery("UPDATE vtiger_inventoryproductrel SET incrementondel = 1 WHERE id=?",array($adb->query_result($invoiceids,$i,"invoiceid")));
  819. }
  820. $emm->addEntityMethod("SalesOrder","UpdateInventory","include/InventoryHandler.php","handleInventoryProductRel");//Adding EntityMethod for Updating Products data after creating SalesOrder
  821. $emm->addEntityMethod("Invoice","UpdateInventory","include/InventoryHandler.php","handleInventoryProductRel");//Adding EntityMethod for Updating Products data after creating Invoice
  822. $vtWorkFlow = new VTWorkflowManager($adb);
  823. $invWorkFlow = $vtWorkFlow->newWorkFlow("Invoice");
  824. $invWorkFlow->test = '[{"fieldname":"subject","operation":"does not contain","value":"`!`"}]';
  825. $invWorkFlow->description = "UpdateInventoryProducts On Every Save";
  826. $vtWorkFlow->save($invWorkFlow);
  827. $tm = new VTTaskManager($adb);
  828. $task = $tm->createTask('VTEntityMethodTask', $invWorkFlow->id);
  829. $task->active=true;
  830. $task->methodName = "UpdateInventory";
  831. $tm->saveTask($task);
  832. /* Support to track if a module is of CrmEntity type or not */
  833. ExecuteQuery("ALTER TABLE vtiger_tab ADD COLUMN isentitytype INT NOT NULL DEFAULT 1");
  834. ExecuteQuery("UPDATE vtiger_tab SET isentitytype=0 WHERE name IN ('Home','Dashboard','Rss','Reports','Portal','Users','Recyclebin')");
  835. /* Support for different languages to be stored in database instead of config file - Vtlib */
  836. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_language(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50), " .
  837. "prefix VARCHAR(10), label VARCHAR(30), lastupdated DATETIME, sequence INT, isdefault INT(1), active INT(1)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  838. /* Register default language English. This will automatically register all the other langauges from config file */
  839. require_once('vtlib/Vtiger/Language.php');
  840. $vtlanguage = new Vtiger_Language();
  841. $vtlanguage->register('en_us','US English','English',true,true,true);
  842. /* To store relationship between the modules in a common table */
  843. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_crmentityrel (crmid int(11) NOT NULL, module varchar(100) NOT NULL, relcrmid int(11) NOT NULL, relmodule varchar(100) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  844. /* To store the field to module relationship for uitype 10 */
  845. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_fieldmodulerel (fieldid int(11) NOT NULL, module varchar(100) NOT NULL, relmodule varchar(100) NOT NULL,
  846. status varchar(10) default NULL, sequence int(11) default NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  847. /* Making users and groups depends on vtiger_users_seq */
  848. $max_grp_id = $adb->query("SELECT MAX(groupid) as maxid from vtiger_groups");
  849. $maxid = $adb->query_result($max_grp_id,0,"maxid");
  850. $user_result = $adb->query("select max(id) as userid from vtiger_users");
  851. $inc_num = $adb->query_result($user_result,0,"userid");
  852. $adb->getUniqueId("vtiger_users");//Creates vtiger_users_seq table if not exists.
  853. $seq_id = $inc_num+$maxid;
  854. $adb->pquery("UPDATE vtiger_users_seq SET id=?",array($seq_id));
  855. $tab_info = array(
  856. "vtiger_group2grouprel"=>array("fk_2_vtiger_group2grouprel","(groupid)","vtiger_groups(groupid)"),
  857. "vtiger_users2group"=>array("fk_1_vtiger_users2group","(groupid)","vtiger_groups(groupid)"),
  858. "vtiger_group2role"=>array("fk_1_vtiger_group2role","(groupid)","vtiger_groups(groupid)"),
  859. "vtiger_group2rs"=>array("fk_1_vtiger_group2rs","(groupid)","vtiger_groups(groupid)"),
  860. "vtiger_datashare_grp2grp"=>array("fk_2_vtiger_datashare_grp2grp","(share_groupid)","vtiger_groups(groupid)"),
  861. "vtiger_datashare_grp2grp"=>array("fk_3_vtiger_datashare_grp2grp","(to_groupid)","vtiger_groups(groupid)"),
  862. "vtiger_datashare_grp2role"=>array("fk_2_vtiger_datashare_grp2role","(share_groupid)","vtiger_groups(groupid)"),
  863. "vtiger_datashare_role2group"=>array("fk_2_vtiger_datashare_role2group","(to_groupid)","vtiger_groups(groupid)"),
  864. "vtiger_datashare_grp2rs"=>array("fk_2_vtiger_datashare_grp2rs","(share_groupid)","vtiger_groups(groupid)"),
  865. "vtiger_datashare_rs2grp"=>array("fk_2_vtiger_datashare_rs2grp","(to_groupid)","vtiger_groups(groupid)"),
  866. "vtiger_tmp_read_group_sharing_per"=>array("fk_1_vtiger_tmp_read_group_sharing_per","(sharedgroupid)","vtiger_groups(groupid)"),
  867. "vtiger_tmp_write_group_sharing_per"=>array("fk_1_vtiger_tmp_write_group_sharing_per","(sharedgroupid)","vtiger_groups(groupid)"),
  868. );
  869. $drop_key_array = array("vtiger_group2grouprel","vtiger_datashare_grp2grp");
  870. foreach($tab_info as $table=>$value){
  871. //Update constraints for vtiger_group2grouprel table
  872. if(in_array($table,$drop_key_array)){
  873. ExecuteQuery("ALTER TABLE $table DROP FOREIGN KEY ".$value[0]);
  874. }
  875. ExecuteQuery("ALTER TABLE $table ADD CONSTRAINT ".$value[0]." FOREIGN KEY ".$value[1]." REFERENCES ".$value[2]." ON DELETE CASCADE ON UPDATE CASCADE");
  876. }
  877. $grp_result = $adb->query("select groupid from vtiger_groups ORDER BY groupid ASC");
  878. $num_grps = $adb->num_rows($grp_result);
  879. for($i=$num_grps-1; $i>=0; $i--) {
  880. $oldId = $adb->query_result($grp_result,$i,"groupid");
  881. $newId = $adb->getUniqueId("vtiger_users");
  882. ExecuteQuery("UPDATE vtiger_groups set groupid = $newId where groupid = $oldId");
  883. ExecuteQuery("UPDATE vtiger_users2group set groupid = $newId where groupid = $oldId");
  884. ExecuteQuery("UPDATE vtiger_group2grouprel set groupid = $newId where groupid = $oldId");
  885. ExecuteQuery("UPDATE vtiger_group2role set groupid = $newId where groupid = $oldId");
  886. ExecuteQuery("UPDATE vtiger_group2rs set groupid = $newId where groupid = $oldId");
  887. ExecuteQuery("UPDATE vtiger_datashare_grp2grp set share_groupid = $newId where share_groupid = $oldId");
  888. ExecuteQuery("UPDATE vtiger_datashare_grp2grp set to_groupid = $newId where to_groupid = $oldId");
  889. ExecuteQuery("UPDATE vtiger_datashare_grp2role set share_groupid = $newId where share_groupid = $oldId");
  890. ExecuteQuery("UPDATE vtiger_datashare_grp2rs set share_groupid = $newId where share_groupid = $oldId");
  891. ExecuteQuery("UPDATE vtiger_datashare_role2group set to_groupid = $newId where to_groupid = $oldId");
  892. ExecuteQuery("UPDATE vtiger_datashare_rs2grp set to_groupid = $newId where to_groupid = $oldId");
  893. ExecuteQuery("UPDATE vtiger_tmp_read_group_sharing_per set sharedgroupid = $newId where sharedgroupid = $oldId");
  894. ExecuteQuery("UPDATE vtiger_tmp_write_group_sharing_per set sharedgroupid = $newId where sharedgroupid = $oldId");
  895. }
  896. $sql_result = $adb->query("select crmid,setype from vtiger_crmentity where smownerid=0 order by setype");
  897. $num_rows = $adb->num_rows($sql_result);
  898. $groupTables_array = array (
  899. 'Leads'=>array ('vtiger_leadgrouprelation','leadid'),
  900. 'Accounts'=>array ('vtiger_accountgrouprelation','accountid'),
  901. 'Contacts'=>array ('vtiger_contactgrouprelation','contactid'),
  902. 'Potentials'=>array ('vtiger_potentialgrouprelation','potentialid'),
  903. 'Quotes'=>array ('vtiger_quotegrouprelation','quoteid'),
  904. 'SalesOrder'=>array ('vtiger_sogrouprelation','salesorderid'),
  905. 'Invoice'=>array ('vtiger_invoicegrouprelation','invoiceid'),
  906. 'PurchaseOrder'=>array ('vtiger_pogrouprelation','purchaseorderid'),
  907. 'HelpDesk'=>array ('vtiger_ticketgrouprelation','ticketid'),
  908. 'Campaigns'=>array ('vtiger_campaigngrouprelation','campaignid'),
  909. 'Calendar'=>array ('vtiger_activitygrouprelation','activityid')
  910. );
  911. foreach($groupTables_array as $module=>$index){
  912. $modulereltable = $index[0];
  913. $modulerelindex = $index[1];
  914. ExecuteQuery("update vtiger_crmentity INNER JOIN {$modulereltable} ON vtiger_crmentity.crmid = {$modulereltable}.{$modulerelindex} INNER JOIN vtiger_groups ON vtiger_groups.groupname = {$modulereltable}.groupname set smownerid = vtiger_groups.groupid");
  915. ExecuteQuery("UPDATE vtiger_crmentity SET smownerid=1 WHERE smownerid=0 AND setype='{$module}'");
  916. }
  917. // user-group ends
  918. /* Product Comment was Missing in Inventory PDF's - Fixed this by eliminating column product_description from vtiger_products
  919. * and referring to description column of vtiger_crmentity wherever required */
  920. ExecuteQuery("UPDATE vtiger_crmentity, vtiger_products SET vtiger_crmentity.description=vtiger_products.product_description
  921. WHERE vtiger_products.productid = vtiger_crmentity.crmid");
  922. ExecuteQuery("ALTER TABLE vtiger_products DROP COLUMN product_description");
  923. ExecuteQuery("UPDATE vtiger_field set fieldname='description', columnname='description', tablename='vtiger_crmentity'
  924. WHERE tablename='vtiger_products' AND fieldname='product_description'");
  925. /* Remove Products from all the Main tabs except for Inventory */
  926. $productTabId = getTabid('Products');
  927. $inventoryTabRes = $adb->query("SELECT parenttabid FROM vtiger_parenttab WHERE parenttab_label='Inventory'");
  928. if($adb->num_rows($inventoryTabRes)>0){
  929. $inventoryTabId = $adb->query_result($inventoryTabRes, 0, 'parenttabid');
  930. ExecuteQuery("DELETE FROM vtiger_parenttabrel WHERE tabid=$productTabId AND parenttabid != $inventoryTabId");
  931. }
  932. $adb->query("ALTER TABLE vtiger_producttaxrel DROP FOREIGN KEY fk_1_vtiger_producttaxrel");
  933. $adb->query("ALTER TABLE vtiger_pricebookproductrel DROP FOREIGN KEY fk_2_vtiger_pricebookproductrel");
  934. /* Vtlib Changes - Table added to store different types of links */
  935. /*ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_links (linkid INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
  936. tabid INT, linktype VARCHAR(20), linklabel VARCHAR(30), linkurl VARCHAR(255), linkicon VARCHAR(100), sequence INT) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  937. ExecuteQuery("CREATE INDEX link_tabidtype_idx ON vtiger_links(tabid,linktype)");*/
  938. /* Column added to vtiger_tab to track the version of the module */
  939. if(!in_array('version', $adb->getColumnNames('vtiger_tab'))) {
  940. ExecuteQuery("ALTER TABLE vtiger_tab ADD COLUMN version VARCHAR(10)");
  941. }
  942. /*adding the notebook to vtiger*/
  943. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_notebook_contents (userid int(19) not null, notebookid int(19), contents text) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  944. /*notbook changes end*/
  945. /* Move Settings Page Information to Database */
  946. // This function moves the settings page to database
  947. function moveSettingsToDatabase($adb){
  948. $adb->query("drop table if exists vtiger_settings_blocks");
  949. $adb->query("drop table if exists vtiger_settings_field");
  950. $adb->query("CREATE TABLE IF NOT EXISTS vtiger_settings_blocks (blockid int(19), label varchar(250), sequence int(19), primary key pk_vtiger_settings_blocks (blockid)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  951. $adb->query("CREATE TABLE IF NOT EXISTS vtiger_settings_field (fieldid int(19), blockid int(19), name varchar(250), iconpath text, description text, linkto text, sequence int(19), active int(19) default 0,foreign key fk_vtiger_settings_fields (blockid) references vtiger_settings_blocks(blockid) on delete cascade) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  952. //icons for all fields
  953. $icons = array("ico-users.gif",
  954. "ico-roles.gif",
  955. "ico-profile.gif",
  956. "ico-groups.gif",
  957. "shareaccess.gif",
  958. "orgshar.gif",
  959. "audit.gif",
  960. "set-IcoLoginHistory.gif",
  961. "vtlib_modmng.gif",
  962. "picklist.gif",
  963. "ViewTemplate.gif",
  964. "mailmarge.gif",
  965. "notification.gif",
  966. "inventory.gif",
  967. "company.gif",
  968. "ogmailserver.gif",
  969. "backupserver.gif",
  970. "assign.gif",
  971. "currency.gif",
  972. "taxConfiguration.gif",
  973. "system.gif",
  974. "proxy.gif",
  975. "announ.gif",
  976. "set-IcoTwoTabConfig.gif",
  977. "terms.gif",
  978. "settingsInvNumber.gif",
  979. "mailScanner.gif",
  980. "settingsWorkflow.png");
  981. //labels for blocks
  982. $blocks = array('LBL_MODULE_MANAGER',
  983. 'LBL_USER_MANAGEMENT',
  984. 'LBL_STUDIO',
  985. 'LBL_COMMUNICATION_TEMPLATES',
  986. 'LBL_OTHER_SETTINGS');
  987. //field names
  988. $names = array('LBL_USERS',
  989. 'LBL_ROLES',
  990. 'LBL_PROFILES',
  991. 'USERGROUPLIST',
  992. 'LBL_SHARING_ACCESS',
  993. 'LBL_FIELDS_ACCESS',
  994. 'LBL_AUDIT_TRAIL',
  995. 'LBL_LOGIN_HISTORY_DETAILS',
  996. 'VTLIB_LBL_MODULE_MANAGER',
  997. 'LBL_PICKLIST_EDITOR',
  998. 'EMAILTEMPLATES',
  999. 'LBL_MAIL_MERGE',
  1000. 'NOTIFICATIONSCHEDULERS',
  1001. 'INVENTORYNOTIFICATION',
  1002. 'LBL_COMPANY_DETAILS',
  1003. 'LBL_MAIL_SERVER_SETTINGS',
  1004. 'LBL_BACKUP_SERVER_SETTINGS',
  1005. 'LBL_ASSIGN_MODULE_OWNERS',
  1006. 'LBL_CURRENCY_SETTINGS',
  1007. 'LBL_TAX_SETTINGS',
  1008. 'LBL_SYSTEM_INFO',
  1009. 'LBL_PROXY_SETTINGS',
  1010. 'LBL_ANNOUNCEMENT',
  1011. 'LBL_DEFAULT_MODULE_VIEW',
  1012. 'INVENTORYTERMSANDCONDITIONS',
  1013. 'LBL_CUSTOMIZE_MODENT_NUMBER',
  1014. 'LBL_MAIL_SCANNER',
  1015. 'LBL_LIST_WORKFLOWS',);
  1016. $name_blocks = array('LBL_USERS'=>'LBL_USER_MANAGEMENT',
  1017. 'LBL_ROLES'=>'LBL_USER_MANAGEMENT',
  1018. 'LBL_PROFILES'=>'LBL_USER_MANAGEMENT',
  1019. 'USERGROUPLIST'=>'LBL_USER_MANAGEMENT',
  1020. 'LBL_SHARING_ACCESS'=>'LBL_USER_MANAGEMENT',
  1021. 'LBL_FIELDS_ACCESS'=>'LBL_USER_MANAGEMENT',
  1022. 'LBL_AUDIT_TRAIL'=>'LBL_USER_MANAGEMENT',
  1023. 'LBL_LOGIN_HISTORY_DETAILS'=>'LBL_USER_MANAGEMENT',
  1024. 'VTLIB_LBL_MODULE_MANAGER'=>'LBL_STUDIO',
  1025. 'LBL_PICKLIST_EDITOR'=>'LBL_STUDIO',
  1026. 'EMAILTEMPLATES'=>'LBL_COMMUNICATION_TEMPLATES',
  1027. 'LBL_MAIL_MERGE'=>'LBL_COMMUNICATION_TEMPLATES',
  1028. 'NOTIFICATIONSCHEDULERS'=>'LBL_COMMUNICATION_TEMPLATES',
  1029. 'INVENTORYNOTIFICATION'=>'LBL_COMMUNICATION_TEMPLATES',
  1030. 'LBL_COMPANY_DETAILS'=>'LBL_COMMUNICATION_TEMPLATES',
  1031. 'LBL_MAIL_SERVER_SETTINGS'=>'LBL_OTHER_SETTINGS',
  1032. 'LBL_BACKUP_SERVER_SETTINGS'=>'LBL_OTHER_SETTINGS',
  1033. 'LBL_ASSIGN_MODULE_OWNERS'=>'LBL_OTHER_SETTINGS',
  1034. 'LBL_CURRENCY_SETTINGS'=>'LBL_OTHER_SETTINGS',
  1035. 'LBL_TAX_SETTINGS'=>'LBL_OTHER_SETTINGS',
  1036. 'LBL_SYSTEM_INFO'=>'LBL_OTHER_SETTINGS',
  1037. 'LBL_PROXY_SETTINGS'=>'LBL_OTHER_SETTINGS',
  1038. 'LBL_ANNOUNCEMENT'=>'LBL_OTHER_SETTINGS',
  1039. 'LBL_DEFAULT_MODULE_VIEW'=>'LBL_OTHER_SETTINGS',
  1040. 'INVENTORYTERMSANDCONDITIONS'=>'LBL_OTHER_SETTINGS',
  1041. 'LBL_CUSTOMIZE_MODENT_NUMBER'=>'LBL_OTHER_SETTINGS',
  1042. 'LBL_MAIL_SCANNER'=>'LBL_OTHER_SETTINGS',
  1043. 'LBL_LIST_WORKFLOWS'=>'LBL_OTHER_SETTINGS',);
  1044. //description for fields
  1045. $description = array('LBL_USER_DESCRIPTION',
  1046. 'LBL_ROLE_DESCRIPTION',
  1047. 'LBL_PROFILE_DESCRIPTION',
  1048. 'LBL_GROUP_DESCRIPTION',
  1049. 'LBL_SHARING_ACCESS_DESCRIPTION',
  1050. 'LBL_SHARING_FIELDS_DESCRIPTION',
  1051. 'LBL_AUDIT_DESCRIPTION',
  1052. 'LBL_LOGIN_HISTORY_DESCRIPTION',
  1053. 'VTLIB_LBL_MODULE_MANAGER_DESCRIPTION',
  1054. 'LBL_PICKLIST_DESCRIPTION',
  1055. 'LBL_EMAIL_TEMPLATE_DESCRIPTION',
  1056. 'LBL_MAIL_MERGE_DESCRIPTION',
  1057. 'LBL_NOTIF_SCHED_DESCRIPTION',
  1058. 'LBL_INV_NOTIF_DESCRIPTION',
  1059. 'LBL_COMPANY_DESCRIPTION',
  1060. 'LBL_MAIL_SERVER_DESCRIPTION',
  1061. 'LBL_BACKUP_SERVER_DESCRIPTION',
  1062. 'LBL_MODULE_OWNERS_DESCRIPTION',
  1063. 'LBL_CURRENCY_DESCRIPTION',
  1064. 'LBL_TAX_DESCRIPTION',
  1065. 'LBL_SYSTEM_DESCRIPTION',
  1066. 'LBL_PROXY_DESCRIPTION',
  1067. 'LBL_ANNOUNCEMENT_DESCRIPTION',
  1068. 'LBL_DEFAULT_MODULE_VIEW_DESC',
  1069. 'LBL_INV_TANDC_DESCRIPTION',
  1070. 'LBL_CUSTOMIZE_MODENT_NUMBER_DESCRIPTION',
  1071. 'LBL_MAIL_SCANNER_DESCRIPTION',
  1072. 'LBL_LIST_WORKFLOWS_DESCRIPTION');
  1073. $links = array('index.php?module=Administration&action=index&parenttab=Settings',
  1074. 'index.php?module=Settings&action=listroles&parenttab=Settings',
  1075. 'index.php?module=Settings&action=ListProfiles&parenttab=Settings',
  1076. 'index.php?module=Settings&action=listgroups&parenttab=Settings',
  1077. 'index.php?module=Settings&action=OrgSharingDetailView&parenttab=Settings',
  1078. 'index.php?module=Settings&action=DefaultFieldPermissions&parenttab=Settings',
  1079. 'index.php?module=Settings&action=AuditTrailList&parenttab=Settings',
  1080. 'index.php?module=Settings&action=ListLoginHistory&parenttab=Settings',
  1081. 'index.php?module=Settings&action=ModuleManager&parenttab=Settings',
  1082. 'index.php?module=PickList&action=PickList&parenttab=Settings',
  1083. 'index.php?module=Settings&action=listemailtemplates&parenttab=Settings',
  1084. 'index.php?module=Settings&action=listwordtemplates&parenttab=Settings',
  1085. 'index.php?module=Settings&action=listnotificationschedulers&parenttab=Settings',
  1086. 'index.php?module=Settings&action=listinventorynotifications&parenttab=Settings',
  1087. 'index.php?module=Settings&action=OrganizationConfig&parenttab=Settings',
  1088. 'index.php?module=Settings&action=EmailConfig&parenttab=Settings',
  1089. 'index.php?module=Settings&action=BackupServerConfig&parenttab=Settings',
  1090. 'index.php?module=Settings&action=ListModuleOwners&parenttab=Settings',
  1091. 'index.php?module=Settings&action=CurrencyListView&parenttab=Settings',
  1092. 'index.php?module=Settings&action=TaxConfig&parenttab=Settings',
  1093. 'index.php?module=System&action=listsysconfig&parenttab=Settings',
  1094. 'index.php?module=Settings&action=ProxyServerConfig&parenttab=Settings',
  1095. 'index.php?module=Settings&action=Announcements&parenttab=Settings',
  1096. 'index.php?module=Settings&action=DefModuleView&parenttab=Settings',
  1097. 'index.php?module=Settings&action=OrganizationTermsandConditions&parenttab=Settings',
  1098. 'index.php?module=Settings&action=CustomModEntityNo&parenttab=Settings',
  1099. 'index.php?module=Settings&action=MailScanner&parenttab=Settings',
  1100. 'index.php?module=com_vtiger_workflow&action=workflowlist&parenttab=Settings',);
  1101. //insert settings blocks
  1102. $count = count($blocks);
  1103. for($i=0; $i<$count; $i++){
  1104. $adb->query("insert into vtiger_settings_blocks values (".$adb->getUniqueID('vtiger_settings_blocks').", '$blocks[$i]', $i+1)");
  1105. }
  1106. $count = count($icons);
  1107. //insert settings fields
  1108. for($i=0, $seq=1; $i<$count; $i++, $seq++){
  1109. if($i==8 || $i==12 || $i==18) {
  1110. $seq = 1;
  1111. }
  1112. $adb->query("insert into vtiger_settings_field (fieldid, blockid, name, iconpath, description, linkto, sequence) values (".$adb->getUniqueID('vtiger_settings_field').", ".getSettingsBlockId($name_blocks[$names[$i]]).", '$names[$i]', '$icons[$i]', '$description[$i]', '$links[$i]', $seq)");
  1113. }
  1114. //hide the system details tab for now
  1115. $adb->query("update vtiger_settings_field set active=1 where name='LBL_SYSTEM_INFO'");
  1116. }
  1117. //move settings page to database starts
  1118. moveSettingsToDatabase($adb);
  1119. //settings page to database ends
  1120. // END
  1121. /* Email status tracking*/
  1122. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_email_access(crmid INT, mailid INT, accessdate DATE, accesstime TIME) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1123. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_email_track(crmid INT, mailid INT, access_count INT, primary key(crmid, mailid)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1124. $fieldid = $adb->getUniqueID('vtiger_field');
  1125. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) VALUES ('10',".$fieldid.", 'access_count', 'vtiger_email_track', '1', '25', 'access_count', 'Access Count', '1', '0', '0', '100', '6', '21', '3', 'V~O', '1', NULL, 'BAS', 0)");
  1126. addFieldSecurity(10, $fieldid, 'false');
  1127. // END
  1128. /* Reports Revamped */
  1129. ExecuteQuery("ALTER TABLE vtiger_report ADD COLUMN owner int(11) NOT NULL");
  1130. ExecuteQuery("UPDATE vtiger_field INNER JOIN vtiger_field as vtiger_field1 on vtiger_field1.tabid=vtiger_field.tabid SET vtiger_field.block = vtiger_field1.block WHERE vtiger_field.fieldname='faq_answer' and vtiger_field1.fieldname='question' and vtiger_field.tabid=15");
  1131. ExecuteQuery("ALTER TABLE vtiger_report ADD COLUMN sharingtype varchar(200) NOT NULL DEFAULT 'Private'");
  1132. ExecuteQuery("UPDATE vtiger_report SET sharingtype='Public', owner=1");
  1133. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_reportsharing(reportid int(19) not null,shareid int(19) not null,setype varchar(200) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1134. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_reportfilters(filterid int(11) not null,name varchar(200) not null) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1135. ExecuteQuery("INSERT INTO vtiger_reportfilters values(1,'Private')");
  1136. ExecuteQuery("INSERT INTO vtiger_reportfilters values(2,'Public')");
  1137. ExecuteQuery("INSERT INTO vtiger_reportfilters values(3,'Shared')");
  1138. /* Account Hierarchy */
  1139. populateLinks();
  1140. /* Product Bundles Revamping */
  1141. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_inventorysubproductrel(id int(19) NOT NULL, sequence_no INT(10) NOT NULL, productid INT(19) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1142. /* Support for Calendar Custom Fields */
  1143. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_activitycf(activityid INT default '0' primary key) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1144. ExecuteQuery("insert into vtiger_blocks values (".$adb->getUniqueID('vtiger_blocks').",9,'LBL_CUSTOM_INFORMATION',3,0,0,0,0,0,1)");
  1145. ExecuteQuery("insert into vtiger_blocks values (".$adb->getUniqueID('vtiger_blocks').",16,'LBL_CUSTOM_INFORMATION',4,0,0,0,0,0,1)");
  1146. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable) values (16,".$adb->getUniqueID('vtiger_field').",'contactid','vtiger_cntactivityrel',1,'57','contact_id','Contact Name',1,0,0,100,1,19,1,'I~O',1,null,'BAS',1)");
  1147. /* Added new field Help Info for vtiger_field table */
  1148. if(!in_array('helpinfo', $adb->getColumnNames('vtiger_field'))) {
  1149. ExecuteQuery("ALTER TABLE vtiger_field ADD COLUMN helpinfo TEXT");
  1150. }
  1151. /* Add Services and Service Contracts Module */
  1152. // Added Hours and Days fields for HelpDesk module.
  1153. $helpDeskTabid = getTabid('HelpDesk');
  1154. $ttBlockid = getBlockId($helpDeskTabid,'LBL_TICKET_INFORMATION');
  1155. $tt_field1 = $adb->getUniqueID('vtiger_field');
  1156. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable, helpinfo) values ($helpDeskTabid,$tt_field1,'hours','vtiger_troubletickets',1,'1','hours','Hours',1,0,0,100,9,$ttBlockid,1,'I~O',1,null,'BAS',1,
  1157. 'This gives the estimated hours for the Ticket<br> When the same ticket is added to a Service Contract, based on the Tracking Unit of the Service Contract, Used units is updated whenever a ticket is Closed.')");
  1158. addFieldSecurity($helpDeskTabid, $tt_field1);
  1159. ExecuteQuery("ALTER TABLE vtiger_troubletickets ADD COLUMN hours VARCHAR(200)");
  1160. $tt_field2 = $adb->getUniqueID('vtiger_field');
  1161. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable, helpinfo) values ($helpDeskTabid,$tt_field2,'days','vtiger_troubletickets',1,'1','days','Days',1,0,0,100,10,$ttBlockid,1,'I~O',1,null,'BAS',1,
  1162. 'This gives the estimated days for the Ticket<br> When the same ticket is added to a Service Contract, based on the Tracking Unit of the Service Contract, Used units is updated whenever a ticket is Closed.')");
  1163. addFieldSecurity($helpDeskTabid, $tt_field2);
  1164. ExecuteQuery("ALTER TABLE vtiger_troubletickets ADD COLUMN days VARCHAR(200)");
  1165. // Adding fields ends here
  1166. //layout editor changes
  1167. $helpdesktabid = getTabid('HelpDesk');
  1168. $invoicetabid = getTabid('Invoice');
  1169. $salesordertabid = getTabid('SalesOrder');
  1170. $purchaseorder = getTabid('PurchaseOrder');
  1171. $faqtabid = getTabid('Faq');
  1172. $quotes = getTabid('Quotes');
  1173. $contacttabid = getTabid('Contacts');
  1174. $campaigntabid = getTabid('Campaigns');
  1175. $leadtabid = getTabid('Leads');
  1176. $potentialtabid = getTabid('Potentials');
  1177. $pricebooktabid = getTabid('PriceBooks');
  1178. $producttabid = getTabid('Products');
  1179. $vendortabid= getTabid('Vendors');
  1180. $accounttabid = getTabid('Accounts');
  1181. ExecuteQuery("alter table vtiger_blocks add column iscustom int default 0");
  1182. ExecuteQuery("update vtiger_field set presence=2");
  1183. ExecuteQuery("update vtiger_field set presence=0 where quickcreate=0 or fieldname='createdtime' or fieldname='modifiedtime' or typeofdata like '%M';");
  1184. ExecuteQuery("update vtiger_field set presence=0 where fieldname in ('update_log','parent_id','comments','solution') and tabid=$helpdesktabid");
  1185. ExecuteQuery("update vtiger_field set presence=0 where fieldname='potentialname'");
  1186. ExecuteQuery("update vtiger_field set presence=0 where fieldname = 'comments' and tabid = $faqtabid");
  1187. ExecuteQuery("update vtiger_field set typeofdata='I~M',presence=2 where fieldname='account_id' and tabid =$potentialtabid ");
  1188. ExecuteQuery("update vtiger_field set typeofdata='I~M',presence=2 where fieldname='account_id' and tabid =$quotes");
  1189. ExecuteQuery("update vtiger_field set typeofdata='I~M',presence=2 where fieldname='account_id' and tabid =$salesordertabid");
  1190. ExecuteQuery("update vtiger_field set typeofdata='I~M',presence=2 where fieldname='account_id' and tabid =$invoicetabid");
  1191. ExecuteQuery("update vtiger_field set presence=0,quickcreate=2 where fieldname='account_id' and tabid = $contacttabid");
  1192. ExecuteQuery("update vtiger_field set presence=0,quickcreate=0 where fieldname='taxclass' and tabid=$producttabid");
  1193. ExecuteQuery("update vtiger_field set presence = 0,quickcreate=3 where block = $new_block_id "); //for recurring invoice block the fields are always active
  1194. ExecuteQuery("update vtiger_field set quickcreate=3 where fieldname='createdtime' or fieldname='modifiedtime'");
  1195. ExecuteQuery("update vtiger_field set quickcreate=3 where tabid in ($invoicetabid,$salesordertabid,$purchaseorder,$quotes,$faqtabid)");
  1196. ExecuteQuery("update vtiger_field set quickcreate=1 where fieldname in ('subject','account_id','bill_street','ship_street') and tabid= $invoicetabid");
  1197. ExecuteQuery("update vtiger_field set quickcreate=1 where fieldname in ('subject','account_id','bill_street','ship_street') and tabid= $salesordertabid");
  1198. ExecuteQuery("update vtiger_field set quickcreate=1 where fieldname in ('subject','vendor_id','bill_street','ship_street') and tabid = $purchaseorder");
  1199. ExecuteQuery("update vtiger_field set quickcreate=1 where fieldname in ('subject','account_id','bill_street','ship_street') and tabid= $quotes");
  1200. ExecuteQuery("update vtiger_field set masseditable=0 where tabid = $documents_tab_id or fieldname ='createdtime' or fieldname = 'modifiedtime'");
  1201. ExecuteQuery("update vtiger_field set typeofdata='V~O',presence=0 where uitype=4");
  1202. ExecuteQuery("update vtiger_field set quickcreate=3,masseditable=0 where uitype=4 AND displaytype=2");
  1203. ExecuteQuery("update vtiger_field set quickcreate=3 where fieldname='imagename'");
  1204. ExecuteQuery("update vtiger_field set quickcreate=2,presence=2 where fieldname in('website','phone') and tabid = $accounttabid");
  1205. ExecuteQuery("update vtiger_field set quickcreate=2,presence=2 where fieldname in('closingdate','campaigntype','expectedresponse','product_id','campaignstatus') and tabid = $campaigntabid");
  1206. ExecuteQuery("update vtiger_field set quickcreate=2,presence=2 where fieldname in('firstname','phone','email') and tabid = $contacttabid");
  1207. ExecuteQuery("update vtiger_field set quickcreate=2,presence=2 where fieldname in('firstname','phone','email','company') and tabid = $leadtabid ");
  1208. ExecuteQuery("update vtiger_field set quickcreate=2,presence=2 where fieldname in('closingdate','sales_stage','amount','account_id') and tabid = $potentialtabid");
  1209. ExecuteQuery("update vtiger_field set quickcreate=2,presence=2 where fieldname in('active') and tabid = $pricebooktabid");
  1210. ExecuteQuery("update vtiger_field set quickcreate=2,presence=2 where fieldname in('discontinued','unit_price') and tabid = $producttabid");
  1211. ExecuteQuery("update vtiger_field set quickcreate=2,presence=2 where fieldname in('phone','email') and tabid = $vendortabid");
  1212. ExecuteQuery("update vtiger_field set quickcreate=2,presence=2 where fieldname in('ticket_title','ticketstatus') and tabid = $helpdesktabid");
  1213. $faqbasicblock = getBlockId($faqtabid,'LBL_FAQ_INFORMATION');
  1214. ExecuteQuery("update vtiger_field set block = $faqbasicblock ,sequence = 7 where fieldname = 'question' and tabid = $faqtabid");
  1215. ExecuteQuery("update vtiger_field set block = $faqbasicblock ,sequence = 8 where fieldname = 'faq_answer' and tabid = $faqtabid");
  1216. /* Added support for setting a custom view as default per user basis */
  1217. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_user_module_preferences (userid int, tabid int, default_cvid int, primary key(userid, tabid), CONSTRAINT fk_1_vtiger_user_module_preferences FOREIGN KEY (userid) REFERENCES vtiger_users (id) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT fk_2_vtiger_user_module_preferences FOREIGN KEY (tabid) REFERENCES vtiger_tab (tabid) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1218. /* home page related changes */
  1219. if(columnExists("homeorder", "vtiger_users")){
  1220. ExecuteQuery("alter table vtiger_users drop column homeorder");
  1221. }
  1222. if(columnExists("tagcloud_view", "vtiger_users")){
  1223. ExecuteQuery("alter table vtiger_users drop column tagcloud_view");
  1224. }
  1225. if(columnExists("defhomeview", "vtiger_users")){
  1226. ExecuteQuery("alter table vtiger_users drop column defhomeview");
  1227. }
  1228. ExecuteQuery("create table vtiger_home_layout (userid int(19), layout int(19)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1229. /* Add Invoices to the related list of Contacts */
  1230. ExecuteQuery("INSERT INTO vtiger_relatedlists VALUES(".$adb->getUniqueID('vtiger_relatedlists').",". getTabid('Contacts').",".getTabid('Invoice').",'get_invoices',12,'Invoice',0, 'add')");
  1231. /* For Webservices Support */
  1232. require_once 'include/Webservices/Utils.php';
  1233. webserviceMigration();
  1234. /*adding B2C model support*/
  1235. ExecuteQuery("alter table vtiger_potential change accountid related_to int(19)");
  1236. $sql = "select fieldid from vtiger_field where tabid=? and columnname=?";
  1237. $result = $adb->pquery($sql, array(getTabid('Potentials'), 'accountid'));
  1238. $fieldid = $adb->query_result($result,0,"fieldid");
  1239. ExecuteQuery("update vtiger_field set uitype='10', typeofdata='V~M', columnname='related_to', fieldname='related_to',fieldlabel='Related To', presence=0 where fieldid=$fieldid");
  1240. ExecuteQuery("insert into vtiger_fieldmodulerel (fieldid, module, relmodule, status, sequence) values ($fieldid, 'Potentials', 'Accounts', NULL, 0), ($fieldid, 'Potentials', 'Contacts', NULL, 1)");
  1241. ExecuteQuery("update vtiger_cvcolumnlist set columnname='vtiger_potential:related_to:related_to:Potentials_Related_To:V' where columnname='vtiger_account:accountname:accountname:Potentials_Account_Name:V'");
  1242. // Function to populate Links
  1243. function populateLinks() {
  1244. include_once('vtlib/Vtiger/Module.php');
  1245. // Links for Accounts module
  1246. $moduleInstance = Vtiger_Module::getInstance('Accounts');
  1247. // Detail View Custom link
  1248. $moduleInstance->addLink(
  1249. 'DETAILVIEWBASIC', 'LBL_ADD_NOTE',
  1250. 'index.php?module=Documents&action=EditView&return_module=$MODULE$&return_action=DetailView&return_id=$RECORD$&parent_id=$RECORD$',
  1251. 'themes/images/bookMark.gif'
  1252. );
  1253. $moduleInstance->addLink('DETAILVIEWBASIC', 'LBL_SHOW_ACCOUNT_HIERARCHY', 'index.php?module=Accounts&action=AccountHierarchy&accountid=$RECORD$');
  1254. $moduleInstance2 = Vtiger_Module::getInstance('Leads');
  1255. $moduleInstance2->addLink(
  1256. 'DETAILVIEWBASIC', 'LBL_ADD_NOTE',
  1257. 'index.php?module=Documents&action=EditView&return_module=$MODULE$&return_action=DetailView&return_id=$RECORD$&parent_id=$RECORD$',
  1258. 'themes/images/bookMark.gif'
  1259. );
  1260. $moduleInstance3 = Vtiger_Module::getInstance('Contacts');
  1261. $moduleInstance3->addLink(
  1262. 'DETAILVIEWBASIC', 'LBL_ADD_NOTE',
  1263. 'index.php?module=Documents&action=EditView&return_module=$MODULE$&return_action=DetailView&return_id=$RECORD$&parent_id=$RECORD$',
  1264. 'themes/images/bookMark.gif'
  1265. );
  1266. }
  1267. /* For Webservices Support */
  1268. function webserviceMigration(){
  1269. global $adb;
  1270. require_once 'include/utils/CommonUtils.php';
  1271. require_once 'include/Webservices/Utils.php';
  1272. $fieldTypeInfo = array('picklist'=>array(15,16),'text'=>array(19,20,21,24),'autogenerated'=>array(3),'phone'=>array(11),
  1273. 'multipicklist'=>array(33),'url'=>array(17),'skype'=>array(85),'boolean'=>array(56,156),
  1274. 'owner'=>array(53),'file'=>array(61,28));
  1275. $referenceMapping = array("50"=>array("Accounts"),"51"=>array("Accounts"),"57"=>array("Contacts"),"58"=>array("Campaigns"),
  1276. "73"=>array("Accounts"),"75"=>array("Vendors"),"76"=>array("Potentials"),"78"=>array("Quotes"),
  1277. "80"=>array("SalesOrder"),"81"=>array("Vendors"),"101"=>array("Users"),"52"=>array("Users"),
  1278. "357"=>array("Contacts","Accounts","Leads","Users","Vendors"),"59"=>array("Products"),
  1279. "66"=>array("Leads","Accounts","Potentials","HelpDesk"),"77"=>array("Users"),"68"=>array("Contacts","Accounts"),
  1280. "117"=>array('Currency'),"116"=>array('Currency'),'26'=>array('DocumentFolders'),'10'=>array());
  1281. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_ws_fieldtype(fieldtypeid integer(19) not null auto_increment,uitype varchar(30)not null,fieldtype varchar(200) not null,PRIMARY KEY(fieldtypeid),UNIQUE KEY uitype_idx (uitype)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1282. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_ws_referencetype(fieldtypeid integer(19) not null,type varchar(25) not null,PRIMARY KEY(fieldtypeid,type), CONSTRAINT `fk_1_vtiger_referencetype` FOREIGN KEY (`fieldtypeid`) REFERENCES `vtiger_ws_fieldtype` (`fieldtypeid`) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1283. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_ws_userauthtoken(userid integer(19) not null,token varchar(25) not null,expiretime INTEGER(19),PRIMARY KEY(userid,expiretime),UNIQUE KEY userid_idx (userid)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1284. ExecuteQuery("alter table vtiger_users add column accesskey varchar(36);");
  1285. $fieldid = $adb->getUniqueID("vtiger_field");
  1286. $usersTabId = getTabid("Users");
  1287. $user_adv_block_id = getBlockId($usersTabId,'LBL_USER_ADV_OPTIONS');
  1288. ExecuteQuery("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable, helpinfo) values($usersTabId,$fieldid,'accesskey','vtiger_users',1,3,'accesskey','Webservice Access Key',1,0,0,100,2,$user_adv_block_id,2,'V~O',1,null,'BAS',0,'Webservice Access Key');");
  1289. foreach($referenceMapping as $uitype=>$referenceArray){
  1290. $success = true;
  1291. $result = $adb->pquery("insert into vtiger_ws_fieldtype(uitype,fieldtype) values(?,?)",array($uitype,"reference"));
  1292. if(!is_object($result)){
  1293. $success=false;
  1294. }
  1295. $result = $adb->pquery("select * from vtiger_ws_fieldtype where uitype=?",array($uitype));
  1296. $rowCount = $adb->num_rows($result);
  1297. for($i=0;$i<$rowCount;$i++){
  1298. $fieldTypeId = $adb->query_result($result,$i,"fieldtypeid");
  1299. foreach($referenceArray as $index=>$referenceType){
  1300. $result = $adb->pquery("insert into vtiger_ws_referencetype(fieldtypeid,type) values(?,?)",array($fieldTypeId,$referenceType));
  1301. if(!is_object($result)){
  1302. echo "failed for: $referenceType, uitype: $fieldTypeId";
  1303. $success=false;
  1304. }
  1305. }
  1306. }
  1307. if(!$success){
  1308. echo "Migration Query Failed";
  1309. break;
  1310. }
  1311. }
  1312. foreach($fieldTypeInfo as $type=>$uitypes){
  1313. foreach($uitypes as $uitype){
  1314. $result = $adb->pquery("insert into vtiger_ws_fieldtype(uitype,fieldtype) values(?,?)",array($uitype,$type));
  1315. if(!is_object($result)){
  1316. "Query for fieldtype details($uitype:uitype,$type:fieldtype)";
  1317. }
  1318. }
  1319. }
  1320. $sql = "select * from vtiger_users";
  1321. $updateQuery = "update vtiger_users set accesskey=? where id=?";
  1322. $result = $adb->pquery($sql,array());
  1323. $rowCount = $adb->num_rows($result);
  1324. for($i=0;$i<$rowCount;$i++){
  1325. $userId = $adb->query_result($result,$i,"id");
  1326. $insertResult = $adb->pquery($updateQuery,array(vtws_generateRandomAccessKey(16),$userId));
  1327. if(!is_object($insertResult)){
  1328. echo "failed for user: ".$adb->query_result($result,$i,"user_name");
  1329. break;
  1330. }
  1331. }
  1332. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_ws_entity(id integer(11) not null auto_increment PRIMARY
  1333. KEY,name varchar(25) not null UNIQUE,handler_path varchar(255) NOT NULL,handler_class varchar(64) NOT NULL,
  1334. ismodule int(3) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1335. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_ws_entity_name(entity_id integer(11) not null PRIMARY
  1336. KEY,name_fields varchar(50),index_field varchar(50),table_name varchar(50)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1337. $names = vtws_getModuleNameList();
  1338. $moduleHandler = array('file'=>'include/Webservices/VtigerModuleOperation.php',
  1339. 'class'=>'VtigerModuleOperation');
  1340. foreach ($names as $tab){
  1341. if(in_array($tab,array('Rss','Webmails','Recyclebin'))){
  1342. continue;
  1343. }
  1344. $entityId = $adb->getUniqueID("vtiger_ws_entity");
  1345. $adb->pquery('insert into vtiger_ws_entity(id,name,handler_path,handler_class,ismodule) values (?,?,?,?,?)',
  1346. array($entityId,$tab,$moduleHandler['file'],$moduleHandler['class'],1));
  1347. }
  1348. $entityId = $adb->getUniqueID("vtiger_ws_entity");
  1349. $adb->pquery('insert into vtiger_ws_entity(id,name,handler_path,handler_class,ismodule) values (?,?,?,?,?)',
  1350. array($entityId,'Events',$moduleHandler['file'],$moduleHandler['class'],1));
  1351. $entityId = $adb->getUniqueID("vtiger_ws_entity");
  1352. $adb->pquery('insert into vtiger_ws_entity(id,name,handler_path,handler_class,ismodule) values (?,?,?,?,?)',
  1353. array($entityId,'Users',$moduleHandler['file'],$moduleHandler['class'],1));
  1354. vtws_addDefaultActorTypeEntity('Groups',array('fieldNames'=>'groupname',
  1355. 'indexField'=>'groupid','tableName'=>'vtiger_groups'));
  1356. ExecuteQuery("CREATE TABLE IF NOT EXISTS `vtiger_ws_entity_tables` (`webservice_entity_id` int(11) NOT NULL ,`table_name` varchar(50) NOT NULL , PRIMARY KEY (`webservice_entity_id`,`table_name`), CONSTRAINT `fk_1_vtiger_ws_actor_tables` FOREIGN KEY (`webservice_entity_id`) REFERENCES `vtiger_ws_entity` (`id`) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8");
  1357. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_ws_entity_fieldtype(fieldtypeid integer(19) not null auto_increment,table_name varchar(50) not null,field_name varchar(50) not null,fieldtype varchar(200) not null,PRIMARY KEY(fieldtypeid),UNIQUE KEY vtiger_idx_1_tablename_fieldname (table_name,field_name)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1358. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_ws_entity_referencetype(fieldtypeid integer(19) not null,type varchar(25) not null,PRIMARY KEY(fieldtypeid,type), CONSTRAINT `vtiger_fk_1_actors_referencetype` FOREIGN KEY (`fieldtypeid`) REFERENCES `vtiger_ws_entity_fieldtype` (`fieldtypeid`) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1359. require_once("include/Webservices/WebServiceError.php");
  1360. require_once 'include/Webservices/VtigerWebserviceObject.php';
  1361. $webserviceObject = VtigerWebserviceObject::fromName($adb,'Groups');
  1362. ExecuteQuery("insert into vtiger_ws_entity_tables(webservice_entity_id,table_name) values ({$webserviceObject->getEntityId()},'vtiger_groups')");
  1363. ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_ws_operation(operationid int(11) not null auto_increment PRIMARY KEY,name varchar(128)
  1364. not null UNIQUE,handler_path varchar(255),handler_method varchar(64), type varchar(8) not null,prelogin int(3) not null, KEY vtiger_idx_ws_oepration_prelogin (prelogin)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1365. ExecuteQuery("CREATE TABLE IF NOT EXISTS `vtiger_ws_operation_parameters` (`operationid` int(11) NOT NULL, `name` varchar(128) NOT NULL,
  1366. `type` varchar(64) NOT NULL, sequence int(11) not null,PRIMARY KEY (`operationid`,`name`), CONSTRAINT
  1367. `vtiger_fk_1_ws_operation_params` FOREIGN KEY (`operationid`) REFERENCES `vtiger_ws_operation` (`operationid`)
  1368. ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1369. $operationMeta = array(
  1370. "login"=>array(
  1371. "include"=>array(
  1372. "include/Webservices/Login.php"
  1373. ),
  1374. "handler"=>"vtws_login",
  1375. "params"=>array(
  1376. "username"=>"String",
  1377. "accessKey"=>"String"
  1378. ),
  1379. "prelogin"=>1,
  1380. "type"=>"POST"
  1381. ),
  1382. "retrieve"=>array(
  1383. "include"=>array(
  1384. "include/Webservices/Retrieve.php"
  1385. ),
  1386. "handler"=>"vtws_retrieve",
  1387. "params"=>array(
  1388. "id"=>"String"
  1389. ),
  1390. "prelogin"=>0,
  1391. "type"=>"GET"
  1392. ),
  1393. "create"=>array(
  1394. "include"=>array(
  1395. "include/Webservices/Create.php"
  1396. ),
  1397. "handler"=>"vtws_create",
  1398. "params"=>array(
  1399. "elementType"=>"String",
  1400. "element"=>"encoded"
  1401. ),
  1402. "prelogin"=>0,
  1403. "type"=>"POST"
  1404. ),
  1405. "update"=>array(
  1406. "include"=>array(
  1407. "include/Webservices/Update.php"
  1408. ),
  1409. "handler"=>"vtws_update",
  1410. "params"=>array(
  1411. "element"=>"encoded"
  1412. ),
  1413. "prelogin"=>0,
  1414. "type"=>"POST"
  1415. ),
  1416. "delete"=>array(
  1417. "include"=>array(
  1418. "include/Webservices/Delete.php"
  1419. ),
  1420. "handler"=>"vtws_delete",
  1421. "params"=>array(
  1422. "id"=>"String"
  1423. ),
  1424. "prelogin"=>0,
  1425. "type"=>"POST"
  1426. ),
  1427. "sync"=>array(
  1428. "include"=>array(
  1429. "include/Webservices/GetUpdates.php"
  1430. ),
  1431. "handler"=>"vtws_sync",
  1432. "params"=>array(
  1433. "modifiedTime"=>"DateTime",
  1434. "elementType"=>"String"
  1435. ),
  1436. "prelogin"=>0,
  1437. "type"=>"GET"
  1438. ),
  1439. "query"=>array(
  1440. "include"=>array(
  1441. "include/Webservices/Query.php"
  1442. ),
  1443. "handler"=>"vtws_query",
  1444. "params"=>array(
  1445. "query"=>"String"
  1446. ),
  1447. "prelogin"=>0,
  1448. "type"=>"GET"
  1449. ),
  1450. "logout"=>array(
  1451. "include"=>array(
  1452. "include/Webservices/Logout.php"
  1453. ),
  1454. "handler"=>"vtws_logout",
  1455. "params"=>array(
  1456. "sessionName"=>"String"
  1457. ),
  1458. "prelogin"=>0,
  1459. "type"=>"POST"
  1460. ),
  1461. "listtypes"=>array(
  1462. "include"=>array(
  1463. "include/Webservices/ModuleTypes.php"
  1464. ),
  1465. "handler"=>"vtws_listtypes",
  1466. "params"=>array(),
  1467. "prelogin"=>0,
  1468. "type"=>"GET"
  1469. ),
  1470. "getchallenge"=>array(
  1471. "include"=>array(
  1472. "include/Webservices/AuthToken.php"
  1473. ),
  1474. "handler"=>"vtws_getchallenge",
  1475. "params"=>array(
  1476. "username"=>"String"
  1477. ),
  1478. "prelogin"=>1,
  1479. "type"=>"GET"
  1480. ),
  1481. "describe"=>array(
  1482. "include"=>array(
  1483. "include/Webservices/DescribeObject.php"
  1484. ),
  1485. "handler"=>"vtws_describe",
  1486. "params"=>array(
  1487. "elementType"=>"String"
  1488. ),
  1489. "prelogin"=>0,
  1490. "type"=>"GET"
  1491. ),
  1492. "extendsession"=>array(
  1493. "include"=>array(
  1494. "include/Webservices/ExtendSession.php"
  1495. ),
  1496. "handler"=>"vtws_extendSession",
  1497. 'params'=>array(),
  1498. "prelogin"=>1,
  1499. "type"=>"POST"
  1500. )
  1501. );
  1502. $createOperationQuery = "insert into vtiger_ws_operation(operationid,name,handler_path,handler_method,type,prelogin)
  1503. values (?,?,?,?,?,?);";
  1504. $createOperationParamsQuery = "insert into vtiger_ws_operation_parameters(operationid,name,type,sequence)
  1505. values (?,?,?,?);";
  1506. foreach ($operationMeta as $operationName => $operationDetails) {
  1507. $operationId = $adb->getUniqueID("vtiger_ws_operation");
  1508. $result = $adb->pquery($createOperationQuery,array($operationId,$operationName,$operationDetails['include'],
  1509. $operationDetails['handler'],$operationDetails['type'],$operationDetails['prelogin']));
  1510. $params = $operationDetails['params'];
  1511. $sequence = 1;
  1512. foreach ($params as $paramName => $paramType) {
  1513. $result = $adb->pquery($createOperationParamsQuery,array($operationId,$paramName,$paramType,$sequence++));
  1514. }
  1515. }
  1516. vtws_addDefaultActorTypeEntity('Currency',array('fieldNames'=>'currency_name',
  1517. 'indexField'=>'id','tableName'=>'vtiger_currency_info'));
  1518. require_once 'include/Webservices/VtigerWebserviceObject.php';
  1519. $webserviceObject = VtigerWebserviceObject::fromName($adb,'Currency');
  1520. ExecuteQuery("insert into vtiger_ws_entity_tables(webservice_entity_id,table_name) values ({$webserviceObject->getEntityId()},'vtiger_currency_info')");
  1521. vtws_addDefaultActorTypeEntity('DocumentFolders',array('fieldNames'=>'foldername',
  1522. 'indexField'=>'folderid','tableName'=>'vtiger_attachmentsfolder'));
  1523. $webserviceObject = VtigerWebserviceObject::fromName($adb,'DocumentFolders');
  1524. ExecuteQuery("insert into vtiger_ws_entity_tables(webservice_entity_id,table_name) values ({$webserviceObject->getEntityId()},'vtiger_attachmentsfolder')");
  1525. $success = true;
  1526. $fieldTypeId = $adb->getUniqueID("vtiger_ws_entity_fieldtype");
  1527. $result = $adb->pquery("insert into vtiger_ws_entity_fieldtype(fieldtypeid,table_name,field_name,fieldtype) values(?,?,?,?);",
  1528. array($fieldTypeId,'vtiger_attachmentsfolder','createdby',"reference"));
  1529. if(!is_object($result)){
  1530. echo "failed fo init<br>";
  1531. $success=false;
  1532. }
  1533. $result = $adb->pquery("insert into vtiger_ws_entity_referencetype(fieldtypeid,type) values(?,?)",array($fieldTypeId,'Users'));
  1534. if(!is_object($result)){
  1535. echo "failed for: Users, fieldtypeid: $fieldTypeId";
  1536. $success=false;
  1537. }
  1538. if(!$success){
  1539. echo "Migration Query Failed";
  1540. }
  1541. }
  1542. ExecuteQuery("ALTER TABLE vtiger_notes MODIFY filename varchar(200)");
  1543. $todoid = getTabid('Calendar');
  1544. $eventid = getTabid('Events');
  1545. // Assigned To field should always come in quickcreate otherwise smownerid will not be filled
  1546. Executequery("UPDATE vtiger_field set quickcreate = 0,quickcreatesequence = 4 WHERE fieldname = 'assigned_user_id' AND tabid = $accounttabid");
  1547. Executequery("UPDATE vtiger_field set quickcreate = 0,quickcreatesequence = 6 WHERE fieldname = 'assigned_user_id' AND tabid = $leadtabid");
  1548. Executequery("UPDATE vtiger_field set quickcreate = 0,quickcreatesequence = 6 WHERE fieldname = 'assigned_user_id' AND tabid = $contacttabid");
  1549. Executequery("UPDATE vtiger_field set quickcreate = 0,quickcreatesequence = 6 WHERE fieldname = 'assigned_user_id' AND tabid = $potentialtabid");
  1550. Executequery("UPDATE vtiger_field set quickcreate = 0,quickcreatesequence = 7 WHERE fieldname = 'assigned_user_id' AND tabid = $campaigntabid");
  1551. Executequery("UPDATE vtiger_field set quickcreate = 0,quickcreatesequence = 4 WHERE fieldname = 'assigned_user_id' AND tabid = $helpdesktabid");
  1552. Executequery("UPDATE vtiger_field set quickcreatesequence = 3 WHERE fieldname = 'ticketpriorities' AND tabid = $helpdesktabid");
  1553. Executequery("UPDATE vtiger_field set quickcreatesequence = 2 WHERE fieldname = 'ticketstatus' AND tabid = $helpdesktabid");
  1554. Executequery("UPDATE vtiger_field set quickcreate = 0,quickcreatesequence = 4 WHERE fieldname ='assigned_user_id' AND tabid = $todoid");
  1555. Executequery("UPDATE vtiger_field set quickcreate = 0,quickcreatesequence = 6 WHERE fieldname ='assigned_user_id' AND tabid = $eventid");
  1556. include_once('modules/Utilities/Currencies.php');
  1557. ExecuteQuery("CREATE TABLE vtiger_currencies(currencyid INTEGER(19),currency_name varchar(200),currency_code varchar(50),currency_symbol varchar(11)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
  1558. foreach($currencies as $key=>$value){
  1559. ExecuteQuery("insert into vtiger_currencies values(".$adb->getUniqueID("vtiger_currencies").",'$key','".$value[0]."','".$value[1]."')");
  1560. }
  1561. $cur_result = $adb->query("SELECT * from vtiger_currency_info");
  1562. for($i=0;$i<$adb->num_rows($cur_result);$i++){
  1563. $cur_symbol = $adb->query_result($cur_result,$i,"currency_symbol");
  1564. $cur_code = $adb->query_result($cur_result,$i,"currency_code");
  1565. $cur_name = $adb->query_result($cur_result,$i,"currency_name");
  1566. $cur_id = $adb->query_result($cur_result,$i,"id");
  1567. $currency_exists = $adb->pquery("SELECT * from vtiger_currencies WHERE currency_code=?",array($cur_code));
  1568. if($adb->num_rows($currency_exists)>0){
  1569. $currency_name = $adb->query_result($currency_exists,0,"currency_name");
  1570. ExecuteQuery("UPDATE vtiger_currency_info SET vtiger_currency_info.currency_name = '$currency_name' WHERE id=$cur_id");
  1571. } else {
  1572. ExecuteQuery("insert into vtiger_currencies values(".$adb->getUniqueID("vtiger_currencies").",'$cur_name','$cur_code','$cur_symbol')");
  1573. }
  1574. }
  1575. Executequery("UPDATE vtiger_products set handler = 1 WHERE handler = 0");
  1576. //Emails fields
  1577. $email_Tabid = getTabid('Emails');
  1578. $blockid = $adb->getUniqueID('vtiger_blocks');
  1579. $adb->query("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable, helpinfo) values($email_Tabid,".$adb->getUniqueID("vtiger_field").",'from_email','vtiger_emaildetails',1,12,'from_email','From',1,2,0,100,1,$blockid,3,'V~M',3,NULL,'BAS',0,NULL)");
  1580. $adb->query("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable, helpinfo) values($email_Tabid,".$adb->getUniqueID("vtiger_field").",'to_email','vtiger_emaildetails',1,8,'saved_toid','To',1,2,0,100,2,$blockid,1,'V~M',3,NULL,'BAS',0,NULL)");
  1581. $adb->query("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable, helpinfo) values($email_Tabid,".$adb->getUniqueID("vtiger_field").",'cc_email','vtiger_emaildetails',1,8,'ccmail','CC',1,2,0,1000,3,$blockid,1,'V~O',3,NULL,'BAS',0,NULL)");
  1582. $adb->query("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable, helpinfo) values($email_Tabid,".$adb->getUniqueID("vtiger_field").",'bcc_email','vtiger_emaildetails',1,8,'bccmail','BCC' ,1,2,0,1000,4,$blockid,1,'V~O',3,NULL,'BAS',0,NULL)");
  1583. $adb->query("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable, helpinfo) values($email_Tabid,".$adb->getUniqueID("vtiger_field").",'idlists','vtiger_emaildetails',1,1,'parent_id','Parent ID' ,1,2,0,1000,5,$blockid,3,'V~O',3,NULL,'BAS',0,NULL)");
  1584. $adb->query("insert into vtiger_field (tabid, fieldid, columnname, tablename, generatedtype, uitype, fieldname, fieldlabel, readonly, presence, selected, maximumlength, sequence, block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, masseditable, helpinfo) values($email_Tabid,".$adb->getUniqueID("vtiger_field").",'email_flag','vtiger_emaildetails',1,16,'email_flag','Email Flag' ,1,2,0,1000,6,$blockid,3,'V~O',3,NULL,'BAS',0,NULL)");
  1585. require_once('include/Zend/Json.php');
  1586. $json = new Zend_Json();
  1587. $result = $adb->query("SELECT * FROM vtiger_emaildetails");
  1588. $rows = $adb->num_rows($result);
  1589. for($i=0 ; $i<$rows ;$i++) {
  1590. $emailid = $adb->query_result($result,$i,'emailid');
  1591. $to = $adb->query_result($result,$i,'to_email');
  1592. $cc = $adb->query_result($result,$i,'cc_email');
  1593. $bcc = $adb->query_result($result,$i,'bcc_email');
  1594. $to = preg_replace("/###/",",",$to);
  1595. $to = str_replace('&amp;lt;','<',$to);
  1596. $to = str_replace('&amp;gt;','>',$to);
  1597. $to = explode(',',$to);
  1598. $to_json = $json->encode($to);
  1599. $cc = str_replace('&amp;lt;','<',$cc);
  1600. $cc = str_replace('&amp;gt;','>',$cc);
  1601. $cc = preg_replace("/###/",",",$cc);
  1602. $cc = explode(',',$cc);
  1603. $cc_json = $json->encode($cc);
  1604. $bcc = str_replace('&amp;lt;','<',$bcc);
  1605. $bcc = str_replace('&amp;gt;','>',$bcc);
  1606. $bcc = preg_replace("/###/",",",$bcc);
  1607. $bcc = explode(',',$bcc);
  1608. $bcc_json = $json->encode($bcc);
  1609. $adb->pquery("UPDATE vtiger_emaildetails set to_email = ?, cc_email= ?, bcc_email= ? WHERE emailid = ?",array($to_json,$cc_json,$bcc_json,$emailid));
  1610. }
  1611. //Reports Migration Handling for Older reports - STARTS
  1612. updateReportColumns("vtiger_selectcolumn");
  1613. updateReportColumns("vtiger_relcriteria");
  1614. function updateReportColumns($table){
  1615. global $adb;
  1616. $report_update_array = array(
  1617. "vtiger_campaign"=>"(vtiger_reportmodules.primarymodule='Potentials' OR vtiger_reportmodules.secondarymodules = 'Potentials') AND $table.columnname LIKE '%vtiger_campaign%'",
  1618. "vtiger_vendorRel"=>"$table.columnname LIKE '%vtiger_vendorRel%'",
  1619. "vtiger_potentialRel"=>"$table.columnname LIKE '%vtiger_potentialRel%'",
  1620. );
  1621. foreach($report_update_array as $key=>$where){
  1622. $query = "SELECT vtiger_report.reportid as reportid,$table.columnname AS columnname FROM vtiger_report INNER JOIN $table ON $table.queryid = vtiger_report.reportid INNER JOIN vtiger_reportmodules ON vtiger_reportmodules.reportmodulesid = vtiger_report.reportid WHERE $where";
  1623. $result = $adb->query($query);
  1624. if($adb->num_rows($result) > 0){
  1625. for($i=0;$i<$adb->num_rows($result);$i++){
  1626. $reportid = $adb->query_result($result,$i,"reportid");
  1627. $colname = $adb->query_result($result,$i,"columnname");
  1628. $column_array = split(":",$colname);
  1629. $column = split("_",$column_array[2]);
  1630. $mod_name = $column[0];
  1631. $newcolname = str_replace("$key",$key."$mod_name",$colname);
  1632. ExecuteQuery("UPDATE $table SET columnname = '".$newcolname."' WHERE queryid = ".$reportid." AND columnname = '".$colname."'");
  1633. }
  1634. }
  1635. }
  1636. $query = "SELECT vtiger_reportmodules.primarymodule as primarymodule, vtiger_report.reportid as reportid,$table.columnname AS columnname FROM vtiger_report INNER JOIN $table ON $table.queryid = vtiger_report.reportid INNER JOIN vtiger_reportmodules ON vtiger_reportmodules.reportmodulesid = vtiger_report.reportid WHERE $table.columnname LIKE 'vtiger_products%:products_description:%'";
  1637. $result = $adb->query($query);
  1638. if($adb->num_rows($result) > 0){
  1639. for($i=0;$i<$adb->num_rows($result);$i++){
  1640. $pri_module = $adb->query_result($result,$i,"reportid");
  1641. $reportid = $adb->query_result($result,$i,"reportid");
  1642. $colname = $adb->query_result($result,$i,"columnname");
  1643. $column_array = split(":",$colname);
  1644. if($pri_module!="Products"){
  1645. $column_array[0]='vtiger_crmentityProducts';
  1646. $column_array[1]='description';
  1647. } else {
  1648. $column_array[0]='vtiger_crmentity';
  1649. $column_array[1]='description';
  1650. }
  1651. $newcolname = $column_array[0].":".$column_array[1].":".$column_array[2].":".$column_array[3].":".$column_array[4];
  1652. ExecuteQuery("UPDATE $table SET columnname = '".$newcolname."' WHERE queryid = ".$reportid." AND columnname = '".$colname."'");
  1653. }
  1654. }
  1655. $query = "SELECT vtiger_reportmodules.primarymodule as primarymodule, vtiger_report.reportid as reportid,$table.columnname AS columnname FROM vtiger_report INNER JOIN $table ON $table.queryid = vtiger_report.reportid INNER JOIN vtiger_reportmodules ON vtiger_reportmodules.reportmodulesid = vtiger_report.reportid WHERE $table.columnname LIKE 'vtiger_accountPotentials%:accountname:%:account_id:%'";
  1656. $result = $adb->query($query);
  1657. if($adb->num_rows($result) > 0){
  1658. for($i=0;$i<$adb->num_rows($result);$i++){
  1659. $reportid = $adb->query_result($result,$i,"reportid");
  1660. $colname = $adb->query_result($result,$i,"columnname");
  1661. $column_array = split(":",$colname);
  1662. $column_array[0]='vtiger_potential';
  1663. $column_array[1]='related_to';
  1664. $column_array[2]='Potentials_Related_To';
  1665. $column_array[3]='related_to';
  1666. $newcolname = $column_array[0].":".$column_array[1].":".$column_array[2].":".$column_array[3].":".$column_array[4];
  1667. ExecuteQuery("UPDATE $table SET columnname = '".$newcolname."' WHERE queryid = ".$reportid." AND columnname = '".$colname."'");
  1668. }
  1669. }
  1670. }
  1671. //ENDS
  1672. ExecuteQuery("ALTER TABLE vtiger_inventoryproductrel ADD COLUMN lineitem_id int(19) AUTO_INCREMENT UNIQUE");
  1673. ExecuteQuery("update vtiger_field set typeofdata='V~M' where fieldname='sales_stage' and tabid =$potentialtabid");
  1674. ExecuteQuery("update vtiger_cvcolumnlist set columnname ='vtiger_emaildetails:to_email:saved_toid:Emails_To:V' where columnname ='vtiger_crmentity:smownerid:assigned_user_id:Emails_Sender:V'");
  1675. // for Workflow in settings page of every module
  1676. $module_manager_id = getSettingsBlockId('LBL_MODULE_MANAGER');
  1677. $result = $adb->pquery("SELECT max(sequence) AS maxseq FROM vtiger_settings_field WHERE blockid = ?",array($module_manager_id));
  1678. $maxseq = $adb->query_result($result,0,'maxseq');
  1679. if($maxseq < 0 || $maxseq == NULL){
  1680. $maxseq=1;
  1681. }
  1682. $adb->pquery("INSERT INTO vtiger_settings_field (fieldid, blockid, name, iconpath, description, linkto, sequence) VALUES (?,?,?,?,?,?,?)",array($adb->getUniqueID('vtiger_settings_field'), $module_manager_id, 'LBL_WORKFLOW_LIST', 'settingsWorkflow.png', 'LBL_AVAILABLE_WORKLIST_LIST', 'index.php?module=com_vtiger_workflow&action=workflowlist', $maxseq));
  1683. $migrationlog->debug("\n\nDB Changes from 5.0.4 to 5.1.0 RC -------- Ends \n\n");
  1684. ?>