PageRenderTime 41ms CodeModel.GetById 11ms 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

Large files files are truncated, but you can click here to view the full file

  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_frequenc…

Large files files are truncated, but you can click here to view the full file