PageRenderTime 203ms CodeModel.GetById 51ms RepoModel.GetById 0ms app.codeStats 2ms

/modules/Migration/DBChanges/42P2_to_50.php

https://bitbucket.org/thomashii/vtigercrm-6-for-postgresql
PHP | 4235 lines | 3026 code | 739 blank | 470 comment | 73 complexity | cf57535456211787245b75e9bfe19fc4 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.1, GPL-2.0, GPL-3.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. ********************************************************************************/
  11. ini_set("memory_limit","32M");
  12. global $php_max_execution_time;
  13. set_time_limit($php_max_execution_time);
  14. //This file is used to modify the database from 4.2Patch2 to 5.0 Alpha release
  15. global $conn;
  16. global $migrationlog;
  17. global $query_count, $success_query_count, $failure_query_count;
  18. global $success_query_array, $failure_query_array;
  19. $migrationlog->debug("\n\nDB Changes from 4.2.x to 5.0 GA -------- Starts \n\n");
  20. //Added to put prefix vtiger_ in some of the columns in tables which are used for CV and Reports and field -- 23-06-06
  21. $migrationlog->debug("Going to rename the table names with prefix vtiger_");
  22. include("modules/Migration/rename_tables.php");
  23. $migrationlog->debug("Renaming the table names with prefix vtiger_ has been finished");
  24. $migrationlog->debug("Database Modifications for 4.2 Patch2 ==> 5.0(Alpha) Dev 3 Starts here.");
  25. //These changes have been made in 4.2.3. The following queries have been included who has run the migration from 4.2 Patch2
  26. $wordtemp = $conn->getColumnNames("vtiger_wordtemplates");
  27. if(is_array($wordtemp) && !in_array("templateid",$wordtemp))
  28. {
  29. $wordtemplate_query1 = "alter table vtiger_wordtemplates DROP PRIMARY KEY";
  30. Execute($wordtemplate_query1);
  31. $wordtemplate_query3 = "alter table vtiger_wordtemplates add column templateid integer(19) unsigned auto_increment primary key FIRST";
  32. Execute($wordtemplate_query3);
  33. }
  34. //upto this added to modify the wordtemplates table which will be in the case of migrate from 4.2 Path2.
  35. /****************** 5.0(Alpha) dev version 1 Database changes -- Starts*********************/
  36. //Added the vtiger_announcement table creation to avoid the error
  37. $ann_query = "CREATE TABLE vtiger_announcement (
  38. creatorid int8 NOT NULL,
  39. announcement text,
  40. title varchar(255) default NULL,
  41. time timestamp NOT NULL default CURRENT_TIMESTAMP,
  42. PRIMARY KEY (creatorid)
  43. )";
  44. Execute($ann_query);
  45. //Added Primay Keys for the left out tables
  46. $alter_array1 = Array(
  47. "alter table vtiger_activity_reminder ADD PRIMARY KEY (activity_id,recurringid)",
  48. "alter table vtiger_activitygrouprelation ADD PRIMARY KEY (activityid)",
  49. "alter table vtiger_cvadvfilter ADD PRIMARY KEY (cvid,columnindex)",
  50. "alter table vtiger_cvcolumnlist ADD PRIMARY KEY (cvid,columnindex)",
  51. "alter table vtiger_cvstdfilter ADD PRIMARY KEY (cvid)",
  52. "alter table vtiger_def_org_field ADD PRIMARY KEY (fieldid)",
  53. "alter table vtiger_leadgrouprelation ADD PRIMARY KEY (leadid)",
  54. "alter table vtiger_leadgrouprelation drop key leadgrouprelation_IDX0",
  55. "alter table vtiger_profile2field ADD PRIMARY KEY (profileid,fieldid)",
  56. "alter table vtiger_profile2standardpermissions ADD PRIMARY KEY (profileid,tabid,Operation)",
  57. "alter table vtiger_profile2standardpermissions drop index idx_prof2stad",
  58. "alter table vtiger_profile2utility ADD PRIMARY KEY (profileid,tabid,activityid)",
  59. "alter table vtiger_profile2utility drop index idx_prof2utility",
  60. "alter table vtiger_relcriteria ADD PRIMARY KEY (queryid,columnindex)",
  61. "alter table vtiger_reportdatefilter ADD PRIMARY KEY (datefilterid)",
  62. "alter table vtiger_reportdatefilter DROP INDEX reportdatefilter_IDX0",
  63. "alter table vtiger_reportsortcol ADD PRIMARY KEY (sortcolid,reportid)",
  64. "alter table vtiger_reportsummary ADD PRIMARY KEY (reportsummaryid,summarytype,columnname)",
  65. "drop table vtiger_role2action",
  66. "drop table vtiger_role2tab",
  67. "alter table vtiger_selectcolumn ADD PRIMARY KEY (queryid,columnindex)",
  68. "alter table vtiger_ticketgrouprelation ADD PRIMARY KEY (ticketid)",
  69. "alter table vtiger_ticketstracktime ADD PRIMARY KEY (ticket_id)",
  70. "alter table vtiger_users2group ADD PRIMARY KEY (groupname,userid)",
  71. "alter table vtiger_users2group DROP INDEX idx_users2group",
  72. );
  73. foreach($alter_array1 as $query)
  74. {
  75. Execute($query);
  76. }
  77. //Tables vtiger_profile2globalpermissions, vtiger_actionmapping creation
  78. $create_sql1 ="CREATE TABLE vtiger_profile2globalpermissions (profileid int8 NOT NULL, globalactionid int8 NOT NULL, globalactionpermission int8 default NULL, PRIMARY KEY (profileid, globalactionid)) ";
  79. Execute($create_sql1);
  80. $create_sql2 = "CREATE TABLE vtiger_actionmapping (actionid int8 NOT NULL, actionname varchar(200) NOT NULL, securitycheck int8 default NULL, PRIMARY KEY (actionid,actionname))";
  81. Execute($create_sql2);
  82. //For all Profiles, insert the following entries into vtiger_profile2global permissions table:
  83. $sql = 'select * from vtiger_profile';
  84. $res = $conn->query($sql);
  85. $noofprofiles = $conn->num_rows($res);
  86. for($i=0;$i<$noofprofiles;$i++)
  87. {
  88. $profile_id = $conn->query_result($res,$i,'profileid');
  89. $sql1 = "insert into vtiger_profile2globalpermissions values ($profile_id,1,1)";
  90. $sql2 = "insert into vtiger_profile2globalpermissions values ($profile_id,2,1)";
  91. Execute($sql1);
  92. Execute($sql2);
  93. }
  94. //Removing entries for Dashboard and Home module from vtiger_profile2standardpermissions table
  95. $del_query1 = "delete from vtiger_profile2standardpermissions where tabid in(1,3)";
  96. Execute($del_query1);
  97. //For all Profile do the following insert into vtiger_profile2utility table:
  98. $sql = 'select * from vtiger_profile';
  99. $res = $conn->query($sql);
  100. $noofprofiles = $conn->num_rows($res);
  101. /* Commented by Don. Handled below
  102. for($i=0;$i<$noofprofiles;$i++)
  103. {
  104. $profile_id = $conn->query_result($res,$i,'profileid');
  105. $sql1 = "insert into vtiger_profile2utility values ($profile_id,4,7,0)";
  106. $sql2 = "insert into vtiger_profile2utility values ($profile_id,7,9,0)";
  107. Execute($sql1);
  108. Execute($sql2);
  109. }
  110. */
  111. //Insert Values into action mapping table:
  112. $actionmapping_array = Array(
  113. "insert into vtiger_actionmapping values(0,'Save',0)",
  114. "insert into vtiger_actionmapping values(1,'EditView',0)",
  115. "insert into vtiger_actionmapping values(2,'Delete',0)",
  116. "insert into vtiger_actionmapping values(3,'index',0)",
  117. "insert into vtiger_actionmapping values(4,'DetailView',0)",
  118. "insert into vtiger_actionmapping values(5,'Import',0)",
  119. "insert into vtiger_actionmapping values(6,'Export',0)",
  120. "insert into vtiger_actionmapping values(8,'Merge',0)",
  121. "insert into vtiger_actionmapping values(1,'VendorEditView',1)",
  122. "insert into vtiger_actionmapping values(4,'VendorDetailView',1)",
  123. "insert into vtiger_actionmapping values(0,'SaveVendor',1)",
  124. "insert into vtiger_actionmapping values(2,'DeleteVendor',1)",
  125. "insert into vtiger_actionmapping values(1,'PriceBookEditView',1)",
  126. "insert into vtiger_actionmapping values(4,'PriceBookDetailView',1)",
  127. "insert into vtiger_actionmapping values(0,'SavePriceBook',1)",
  128. "insert into vtiger_actionmapping values(2,'DeletePriceBook',1)",
  129. "insert into vtiger_actionmapping values(1,'SalesOrderEditView',1)",
  130. "insert into vtiger_actionmapping values(4,'SalesOrderDetailView',1)",
  131. "insert into vtiger_actionmapping values(0,'SaveSalesOrder',1)",
  132. "insert into vtiger_actionmapping values(2,'DeleteSalesOrder',1)",
  133. "insert into vtiger_actionmapping values(9,'ConvertLead',0)",
  134. "insert into vtiger_actionmapping values(1,'DetailViewAjax',1)",
  135. "insert into vtiger_actionmapping values(1,'QuickCreate',1)",
  136. "insert into vtiger_actionmapping values(4,'TagCloud',1)"
  137. );
  138. foreach($actionmapping_array as $query)
  139. {
  140. Execute($query);
  141. }
  142. //Added two columns in vtiger_field table to construct the quickcreate form dynamically
  143. $alter_array2 = Array(
  144. "ALTER TABLE vtiger_field ADD column quickcreate int(10) after typeofdata",
  145. "ALTER TABLE vtiger_field ADD column quickcreatesequence int(19) after quickcreate",
  146. );
  147. foreach($alter_array2 as $query)
  148. {
  149. Execute($query);
  150. }
  151. $update_array1 = Array(
  152. "UPDATE vtiger_field SET quickcreate = 1,quickcreatesequence = 0",
  153. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 1 WHERE tabid = 2 and fieldlabel = 'Potential Name'",
  154. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 2 WHERE tabid = 2 and fieldlabel = 'Account Name'",
  155. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 3 WHERE tabid = 2 and fieldlabel = 'Expected Close Date'",
  156. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 4 WHERE tabid = 2 and fieldlabel = 'Sales Stage'",
  157. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 5 WHERE tabid = 2 and fieldlabel = 'Amount'",
  158. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 1 WHERE tabid = 4 and fieldlabel = 'First Name'",
  159. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 2 WHERE tabid = 4 and fieldlabel = 'Last Name'",
  160. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 3 WHERE tabid = 4 and fieldlabel = 'Account Name'",
  161. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 4 WHERE tabid = 4 and fieldlabel = 'Office Phone'",
  162. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 5 WHERE tabid = 4 and fieldlabel = 'Email'",
  163. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 1 WHERE tabid = 6 and fieldlabel = 'Account Name'",
  164. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 2 WHERE tabid = 6 and fieldlabel = 'Phone'",
  165. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 3 WHERE tabid = 6 and fieldlabel = 'Website'",
  166. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 1 WHERE tabid = 7 and fieldlabel = 'First Name'",
  167. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 2 WHERE tabid = 7 and fieldlabel = 'Last Name'",
  168. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 3 WHERE tabid = 7 and fieldlabel = 'Company'",
  169. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 4 WHERE tabid = 7 and fieldlabel = 'Phone'",
  170. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 5 WHERE tabid = 7 and fieldlabel = 'Email'",
  171. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 1 WHERE tabid = 8 and fieldlabel = 'Subject'",
  172. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 1 WHERE tabid = 9 and fieldlabel = 'Subject'",
  173. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 2 WHERE tabid = 9 and fieldlabel = 'Start Date & Time'",
  174. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 1 WHERE tabid = 10 and fieldlabel = 'Subject'",
  175. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 2 WHERE tabid = 10 and fieldlabel = 'Date & Time Sent'",
  176. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 1 WHERE tabid = 13 and fieldlabel = 'Title'",
  177. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 2 WHERE tabid = 13 and fieldlabel = 'Description'",
  178. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 3 WHERE tabid = 13 and fieldlabel = 'Priority'",
  179. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 1 WHERE tabid = 14 and fieldlabel = 'Product Name'",
  180. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 2 WHERE tabid = 14 and fieldlabel = 'Product Code'",
  181. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 3 WHERE tabid = 14 and fieldlabel = 'Product Category'",
  182. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 1 WHERE tabid = 16 and fieldlabel = 'Subject'",
  183. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 2 WHERE tabid = 16 and fieldlabel = 'Start Date & Time'",
  184. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 3 WHERE tabid = 16 and fieldlabel = 'Activity Type'",
  185. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 4 WHERE tabid = 16 and fieldlabel = 'Duration'",
  186. );
  187. foreach($update_array1 as $query)
  188. {
  189. Execute($query);
  190. }
  191. //Added for the "Color By User in Calendar " which has been contributed by Cesar
  192. $alter_query1 = "ALTER TABLE vtiger_users ADD cal_color VARCHAR(25) DEFAULT '#E6FAD8' AFTER user_hash";
  193. Execute($alter_query1);
  194. //code contributed by Fredy for color vtiger_priority
  195. $newfieldid = $conn->getUniqueID("vtiger_field");
  196. $insert_query1 = "insert into vtiger_field values (16,".$newfieldid.",'priority','activity',1,15,'taskpriority','Priority',1,0,0,100,17,1,1,'V~O',1,'')";
  197. Execute($insert_query1);
  198. //Added on 23-12-2005 which is missed from Fredy's contribution for Color vtiger_priority
  199. populateFieldForSecurity('16',$newfieldid);
  200. $activity_cols = $conn->getColumnNames("vtiger_activity");
  201. if(is_array($activity_cols) && !in_array("priority",$activity_cols))
  202. {
  203. $activity_alter_query = "alter table vtiger_activity add column priority varchar(150) default NULL";
  204. Execute($activity_alter_query);
  205. }
  206. //Code contributed by Raju for better emailing
  207. /*
  208. $insert_array1 = Array(
  209. "insert into vtiger_field values (10,".$conn->getUniqueID("vtiger_field").",'crmid','seactivityrel',1,'357','parent_id','Related To',1,0,0,100,1,2,1,'I~O',1,'')",
  210. "insert into vtiger_field values (10,".$conn->getUniqueID("vtiger_field").",'subject','activity',1,'2','subject','Subject',1,0,0,100,1,3,1,'V~M',0,1)",
  211. "insert into vtiger_field values (10,".$conn->getUniqueID("vtiger_field").",'filename','emails',1,'61','filename','Attachment',1,0,0,100,1,4,1,'V~O',1,'')",
  212. "insert into vtiger_field values (10,".$conn->getUniqueID("vtiger_field").",'description','emails',1,'19','description','Description',1,0,0,100,1,5,1,'V~O',1,'')",
  213. );
  214. */
  215. //commented the above array as that queries are wrong queries -- changed on 23-12-2005
  216. $insert_array1 = array(
  217. "update vtiger_field set uitype='357' where tabid=10 and fieldname='parent_id' and tablename='vtiger_seactivityrel'",
  218. "update vtiger_field set sequence=1 where tabid=10 and fieldname in ('parent_id','subject','filename','description')",
  219. "update vtiger_field set block=2 where tabid=10 and fieldname='parent_id'",
  220. "update vtiger_field set block=3 where tabid=10 and fieldname='subject'",
  221. "update vtiger_field set block=4 where tabid=10 and fieldname='filename'",
  222. "update vtiger_field set block=5 where tabid=10 and fieldname='description'",
  223. );
  224. foreach($insert_array1 as $query)
  225. {
  226. Execute($query);
  227. }
  228. //code contributed by mike to rearrange the home page
  229. $alter_query2 = "alter table vtiger_users add column homeorder varchar(255) default 'ALVT,PLVT,QLTQ,CVLVT,HLT,OLV,GRT,OLTSO,ILTI' after date_format";
  230. Execute($alter_query2);
  231. //Added one column in vtiger_invoice table to include 'Contact Name' vtiger_field in Invoice module
  232. $alter_query3 = "ALTER TABLE vtiger_invoice ADD column contactid int(19) after customerno";
  233. Execute($alter_query3);
  234. $newfieldid = $conn->getUniqueID("vtiger_field");
  235. $insert_query2 = "insert into vtiger_field values (23,".$newfieldid.",'contactid','invoice',1,'57','contact_id','Contact Name',1,0,0,100,4,1,1,'I~O',1,'')";
  236. Execute($insert_query2);
  237. //Added on 23-12-2005 because we must populate vtiger_field entries in vtiger_profile2field and vtiger_def_org_field if we add a vtiger_field in vtiger_field table
  238. populateFieldForSecurity('23',$newfieldid);
  239. //changes made to fix the bug in Address Information block of Accounts and Contacs module
  240. $update_array2 = Array(
  241. "UPDATE vtiger_field SET fieldlabel='Billing City', sequence=5 WHERE tabid=6 and fieldname='bill_city'",
  242. "UPDATE vtiger_field SET fieldlabel='Billing State', sequence=7 WHERE tabid=6 and fieldname='bill_state'",
  243. "UPDATE vtiger_field SET fieldlabel='Billing Code', sequence=9 WHERE tabid=6 and fieldname='bill_code'",
  244. "UPDATE vtiger_field SET fieldlabel='Billing Country', sequence=11 WHERE tabid=6 and fieldname='bill_country'",
  245. "UPDATE vtiger_field SET fieldlabel='Shipping City', sequence=6 WHERE tabid=6 and fieldname='ship_city'",
  246. "UPDATE vtiger_field SET fieldlabel='Shipping State', sequence=8 WHERE tabid=6 and fieldname='ship_state'",
  247. "UPDATE vtiger_field SET fieldlabel='Shipping Code', sequence=10 WHERE tabid=6 and fieldname='ship_code'",
  248. "UPDATE vtiger_field SET fieldlabel='Shipping Country', sequence=12 WHERE tabid=6 and fieldname='ship_country'",
  249. "UPDATE vtiger_field SET fieldlabel='Mailing City', sequence=5 WHERE tabid=4 and fieldname='mailingcity'",
  250. "UPDATE vtiger_field SET fieldlabel='Mailing State', sequence=7 WHERE tabid=4 and fieldname='mailingstate'",
  251. "UPDATE vtiger_field SET fieldlabel='Mailing Zip', sequence=9 WHERE tabid=4 and fieldname='mailingzip'",
  252. "UPDATE vtiger_field SET fieldlabel='Mailing Country', sequence=11 WHERE tabid=4 and fieldname='mailingcountry'",
  253. "UPDATE vtiger_field SET fieldlabel='Other City', sequence=6 WHERE tabid=4 and fieldname='othercity'",
  254. "UPDATE vtiger_field SET fieldlabel='Other State', sequence=8 WHERE tabid=4 and fieldname='otherstate'",
  255. "UPDATE vtiger_field SET fieldlabel='Other Zip', sequence=10 WHERE tabid=4 and fieldname='otherzip'",
  256. "UPDATE vtiger_field SET fieldlabel='Other Country', sequence=12 WHERE tabid=4 and fieldname='othercountry'",
  257. );
  258. foreach($update_array2 as $query)
  259. {
  260. Execute($query);
  261. }
  262. //Added vtiger_field emailoptout in vtiger_account table
  263. $newfieldid = $conn->getUniqueID("vtiger_field");
  264. $insert_query3 = "insert into vtiger_field values (6,".$newfieldid.",'emailoptout','account',1,'56','emailoptout','Email Opt Out',1,0,0,100,17,1,1,'C~O',1,'')";
  265. Execute($insert_query3);
  266. //Added on 23-12-2005 because we must populate vtiger_field entries in vtiger_profile2field and vtiger_def_org_field if we add a vtiger_field in vtiger_field table
  267. populateFieldForSecurity('6',$newfieldid);
  268. //Added on 22-12-2005
  269. $alter_query4 = "alter table vtiger_account add column emailoptout varchar(3) default 0";
  270. Execute($alter_query4);
  271. $update_array3 = Array(
  272. "update vtiger_field set sequence=18 where tabid=6 and fieldname ='assigned_user_id'",
  273. "update vtiger_field set sequence=19 where tabid=6 and fieldname ='createdtime'",
  274. "update vtiger_field set sequence=19 where tabid=6 and fieldname ='modifiedtime'",
  275. );
  276. foreach($update_array3 as $query)
  277. {
  278. Execute($query);
  279. }
  280. //create table vtiger_moduleowners to assign the module and corresponding owners
  281. $create_query2 = "CREATE TABLE vtiger_moduleowners (
  282. `tabid` int(19) NOT NULL default '0',
  283. `user_id` varchar(11) NOT NULL,
  284. PRIMARY KEY (`tabid`),
  285. KEY `moduleowners_tabid_user_id_idx` (`tabid`,`user_id`)
  286. ) ENGINE=InnoDB";
  287. /*
  288. $create_query2 = "CREATE TABLE vtiger_moduleowners
  289. (
  290. `tabid` int(19) NOT NULL default '0',
  291. `user_id` varchar(11) NOT NULL default '',
  292. PRIMARY KEY (`tabid`),
  293. CONSTRAINT `fk_ModuleOwners` FOREIGN KEY (`tabid`) REFERENCES `vtiger_tab` (`tabid`) ON DELETE CASCADE
  294. ) TYPE=InnoDB";
  295. */
  296. Execute($create_query2);
  297. //Populated the default entries for vtiger_moduleowners which is created newly
  298. $module_array = Array(
  299. 'Potentials',
  300. 'Contacts',
  301. 'Accounts',
  302. 'Leads',
  303. 'Notes',
  304. 'Activities',
  305. 'Emails',
  306. 'HelpDesk',
  307. 'Products',
  308. 'Faq',
  309. 'Vendor',
  310. 'PriceBook',
  311. 'Quotes',
  312. 'Orders',
  313. 'SalesOrder',
  314. 'Invoice',
  315. 'Reports'
  316. );
  317. foreach($module_array as $mod)
  318. {
  319. $query = "insert into vtiger_moduleowners values(".$this->localGetTabID($mod).",1)";
  320. Execute($query);
  321. }
  322. //Changes made to include status vtiger_field in Activity Quickcreate Form
  323. $update_array4 = Array(
  324. "UPDATE vtiger_field SET quickcreate=0,quickcreatesequence=3 WHERE tabid=16 and fieldname='eventstatus'",
  325. "UPDATE vtiger_field SET quickcreate=0,quickcreatesequence=4 WHERE tabid=16 and fieldname='activitytype'",
  326. "UPDATE vtiger_field SET quickcreate=0,quickcreatesequence=5 WHERE tabid=16 and fieldname='duration_hours'",
  327. "UPDATE vtiger_field SET quickcreate=0,quickcreatesequence=3 WHERE tabid=9 and fieldname='taskstatus'",
  328. );
  329. foreach($update_array4 as $query)
  330. {
  331. Execute($query);
  332. }
  333. //Table 'inventory_tandc' added newly to include Inventory Terms &Conditions
  334. $create_query1 = "CREATE TABLE vtiger_inventory_tandc(id INT(19),type VARCHAR(30) NOT NULL,tandc LONGTEXT default NULL,PRIMARY KEY(id))";
  335. Execute($create_query1);
  336. $insert_query4 = "insert into vtiger_inventory_tandc values('".$conn->getUniqueID('vtiger_inventory_tandc')."','Inventory',' ')";
  337. Execute($insert_query4);
  338. /****************** 5.0(Alpha) dev version 1 Database changes -- Ends*********************/
  339. /****************** 5.0(Alpha) dev version 2 Database changes -- Starts*********************/
  340. $query1 = "ALTER TABLE vtiger_leadaddress change lane lane varchar(250)";
  341. Execute($query1);
  342. $rename_table_array1 = Array(
  343. "update vtiger_field set tablename='vtiger_customerdetails' where tabid=4 and fieldname in ('portal','support_start_date','support_end_date')",
  344. "alter table vtiger_PortalInfo drop foreign key fk_PortalInfo",
  345. "rename table vtiger_PortalInfo to vtiger_portalinfo",
  346. "alter table vtiger_portalinfo add CONSTRAINT `fk_portalinfo` FOREIGN KEY (`id`) REFERENCES `vtiger_contactdetails` (`contactid`) ON DELETE CASCADE",
  347. "alter table vtiger_CustomerDetails drop foreign key fk_CustomerDetails",
  348. "rename table vtiger_CustomerDetails to vtiger_customerdetails",
  349. "alter table vtiger_customerdetails add CONSTRAINT `fk_customerdetails` FOREIGN KEY (`customerid`) REFERENCES `vtiger_contactdetails` (`contactid`) ON DELETE CASCADE"
  350. );
  351. foreach($rename_table_array1 as $query)
  352. {
  353. Execute($query);
  354. }
  355. $query2 = "create table vtiger_ownernotify(crmid int(19),smownerid int(19),flag int(3))";
  356. Execute($query2);
  357. //Form the vtiger_role_map_array as vtiger_roleid=>name mapping array
  358. $sql = "select * from vtiger_role";
  359. $res = $conn->query($sql);
  360. $role_map_array = Array();
  361. for($i=0;$i<$conn->num_rows($res);$i++)
  362. {
  363. $roleid = $conn->query_result($res,$i,'roleid');
  364. $name = $conn->query_result($res,$i,'name');
  365. $role_map_array[$roleid] = $name;
  366. }
  367. $conn->println("List of Roles (roleid => name) ==> ");$conn->println($role_map_array);
  368. //echo '<pre> List of vtiger_roles :';print_r($role_map_array);echo '</pre>';
  369. //Before delete the vtiger_role take a backup array for the table vtiger_user2role
  370. $sql = "select * from vtiger_user2role";
  371. $res = $conn->query($sql);
  372. $user2role_array = array();
  373. for($i=0;$i<$conn->num_rows($res);$i++)
  374. {
  375. $userid = $conn->query_result($res,$i,'userid');
  376. $roleid = $conn->query_result($res,$i,'roleid');
  377. $user2role_array[$userid] = $roleid;
  378. }
  379. $conn->println("Users 2 Roles (userid => roleid) ==> ");$conn->println($user2role_array);
  380. //echo '<pre> List of vtiger_user2role : (userid => vtiger_roleid)';print_r($user2role_array);echo '</pre>';
  381. //Delete the vtiger_role entries
  382. $sql = "truncate vtiger_role";
  383. Execute($sql);
  384. $query3 = "alter table vtiger_user2role drop FOREIGN KEY fk_user2role2";
  385. Execute($query3);
  386. //4,5 th are the Extra added queries
  387. $alter_query_array1 = Array(
  388. "alter table vtiger_user2role change roleid roleid varchar(255)",
  389. "alter table vtiger_role2profile change roleid roleid varchar(255)",
  390. "alter table vtiger_role CHANGE roleid roleid varchar(255)",
  391. "alter table vtiger_role2profile drop PRIMARY KEY",
  392. "alter table vtiger_role2profile ADD PRIMARY KEY (roleid,profileid)"
  393. );
  394. foreach($alter_query_array1 as $query)
  395. {
  396. Execute($query);
  397. }
  398. $query4 = "ALTER TABLE vtiger_user2role ADD CONSTRAINT fk_user2role2 FOREIGN KEY (roleid) REFERENCES vtiger_role(roleid) ON DELETE CASCADE";
  399. Execute($query4);
  400. $alter_query_array2 = Array(
  401. "alter table vtiger_role CHANGE name rolename varchar(200)",
  402. "alter table vtiger_role DROP description",
  403. "alter table vtiger_role add parentrole varchar(255)",
  404. "alter table vtiger_role add depth int(19)"
  405. );
  406. foreach($alter_query_array2 as $query)
  407. {
  408. Execute($query);
  409. }
  410. $query5 = "insert into vtiger_role values('H1','Organisation','H1',0)";
  411. Execute($query5);
  412. //include("include/utils/UserInfoUtil.php");
  413. //Create vtiger_role based on vtiger_role_map_array values and form the new_role_map_array with old vtiger_roleid and new vtiger_roleid
  414. foreach($role_map_array as $roleid => $rolename)
  415. {
  416. $parentRole = 'H1';
  417. if($rolename == 'standard_user')
  418. {
  419. $rs = $conn->query("select * from vtiger_role where rolename='administrator'");
  420. $parentRole = $conn->query_result($rs,0,'roleid');
  421. }
  422. $empty_array = array(""=>"");
  423. $new_role_id = localcreateRole($rolename,$parentRole,$empty_array);
  424. $new_role_map_array[$roleid] = $new_role_id;
  425. }
  426. $conn->println("Roles (oldroleid => newroleid) ==> ");$conn->println($new_role_map_array);
  427. //Before insert the new entry we should remove the old entries -- added on 06-06-06
  428. $user2role_del = "truncate vtiger_user2role";
  429. Execute($user2role_del);
  430. //First we will insert the old values from vtiger_user2role_array to vtiger_user2role table and then update the new vtiger_role id
  431. foreach($user2role_array as $userid => $roleid)
  432. {
  433. $sql = "insert into vtiger_user2role (userid, roleid) values(".$userid.",'".$new_role_map_array[$roleid]."')";
  434. Execute($sql);
  435. }
  436. //Commented the following loop as we have backup the vtiger_user2role and insert the entries with the new rold id using new_role_map_array above
  437. //Update the vtiger_user2role table with new vtiger_roleid
  438. /*
  439. foreach($new_role_map_array as $old_roleid => $new_roleid)
  440. {
  441. $update_user2role = "update vtiger_user2role set vtiger_roleid='".$new_roleid."' where vtiger_roleid=".$old_roleid;
  442. Execute($update_user2role);
  443. }
  444. */
  445. //Update the vtiger_role2profile table with new vtiger_roleid
  446. foreach($new_role_map_array as $old_roleid => $new_roleid)
  447. {
  448. $update_role2profile = "update vtiger_role2profile set roleid='".$new_roleid."' where roleid=".$old_roleid;
  449. Execute($update_role2profile);
  450. }
  451. //Group Migration:
  452. //Step 1 : form and group_map_array as groupname => description from vtiger_groups table
  453. //Step 2 : form an vtiger_users2group_map_array array as userid => groupname from vtiger_users2group table
  454. //Step 3 : delete all entries from vtiger_groups table and enter new values from group_map_array
  455. //Step 4 : drop the table vtiger_users2group and create new table
  456. //Step 5 : put entries to vtiger_users2group table based on vtiger_users2group_map_array. Here get the groupid from vtiger_groups table based on groupname
  457. //Step 1 : Form the group_map_array as groupname => description
  458. $sql = "select * from vtiger_groups";
  459. $res = $conn->query($sql);
  460. $group_map_array = Array();
  461. for($i=0;$i<$conn->num_rows($res);$i++)
  462. {
  463. $name = $conn->query_result($res,$i,'name');
  464. $desc = $conn->query_result($res,$i,'description');
  465. $group_map_array[$name] = $desc;
  466. }
  467. $conn->println("List of Groups (name => description) ==> ");$conn->println($group_map_array);
  468. //echo '<pre>List of Groups : ';print_r($group_map_array);echo '</pre>';
  469. //Step 2 : form an vtiger_users2group_map_array array as userid => groupname from vtiger_users2group table
  470. $sql = "select * from vtiger_users2group";
  471. $res = $conn->query($sql);
  472. $users2group_map_array = Array();
  473. for($i=0;$i<$conn->num_rows($res);$i++)
  474. {
  475. $groupname = $conn->query_result($res,$i,'groupname');
  476. $userid = $conn->query_result($res,$i,'userid');
  477. $users2group_map_array[$userid] = $groupname;
  478. }
  479. $conn->println("Users 2 Groups (userid => groupname) ==> ");$conn->println($users2group_map_array);
  480. //echo '<pre>List of vtiger_users2group : ';print_r($users2group_map_array);echo '</pre>';
  481. //Step 3 : delete all entries from vtiger_groups table
  482. $sql = "truncate vtiger_groups";
  483. Execute($sql);
  484. $alter_query_array3 = Array(
  485. "alter table vtiger_users2group drop FOREIGN KEY fk_users2group",
  486. "alter table vtiger_leadgrouprelation drop FOREIGN KEY fk_leadgrouprelation2",
  487. "alter table vtiger_activitygrouprelation drop FOREIGN KEY fk_activitygrouprelation2",
  488. "alter table vtiger_ticketgrouprelation drop FOREIGN KEY fk_ticketgrouprelation2",
  489. "alter table vtiger_groups drop PRIMARY KEY"
  490. );
  491. foreach($alter_query_array3 as $query)
  492. {
  493. Execute($query);
  494. }
  495. //2 nd query is the Extra added query
  496. //Adding columns in group table:
  497. $alter_query_array4 = Array(
  498. "alter table vtiger_groups add column groupid int(19) FIRST",
  499. "alter table vtiger_groups change name groupname varchar(100)",
  500. "alter table vtiger_groups ADD PRIMARY KEY (groupid)",
  501. "alter table vtiger_groups add index (groupname)"
  502. );
  503. foreach($alter_query_array4 as $query)
  504. {
  505. Execute($query);
  506. }
  507. //Moved the create table queries for vtiger_group2grouprel, vtiger_group2role, vtiger_group2rs from the end of this block
  508. //Added on 06-06-06
  509. $query8 = "CREATE TABLE vtiger_group2grouprel (
  510. `groupid` int(19) NOT NULL,
  511. `containsgroupid` int(19) NOT NULL,
  512. PRIMARY KEY (`groupid`,`containsgroupid`)
  513. ) ENGINE=InnoDB";
  514. /*
  515. $query8 = "CREATE TABLE vtiger_group2grouprel
  516. (
  517. `groupid` int(19) NOT NULL default '0',
  518. `containsgroupid` int(19) NOT NULL default '0',
  519. PRIMARY KEY (`groupid`,`containsgroupid`),
  520. CONSTRAINT `fk_group2grouprel1` FOREIGN KEY (`groupid`) REFERENCES `vtiger_groups` (`groupid`) ON DELETE CASCADE
  521. ) TYPE=InnoDB";
  522. */
  523. Execute($query8);
  524. //Added on 06-06-06
  525. $query9 = "CREATE TABLE vtiger_group2role (
  526. `groupid` int(19) NOT NULL,
  527. `roleid` varchar(255) NOT NULL,
  528. PRIMARY KEY (`groupid`,`roleid`)
  529. ) ENGINE=InnoDB";
  530. /*
  531. $query9 = "CREATE TABLE vtiger_group2role
  532. (
  533. `groupid` int(19) NOT NULL default '0',
  534. `roleid` varchar(255) NOT NULL default '',
  535. PRIMARY KEY (`groupid`,`roleid`),
  536. CONSTRAINT `fk_group2role1` FOREIGN KEY (`groupid`) REFERENCES `vtiger_groups` (`groupid`) ON DELETE CASCADE
  537. ) TYPE=InnoDB";
  538. */
  539. Execute($query9);
  540. //Added on 06-06-06
  541. $query10 = "CREATE TABLE vtiger_group2rs (
  542. `groupid` int(19) NOT NULL,
  543. `roleandsubid` varchar(255) NOT NULL,
  544. PRIMARY KEY (`groupid`,`roleandsubid`)
  545. ) ENGINE=InnoDB";
  546. /*
  547. $query10 = "CREATE TABLE vtiger_group2rs
  548. (
  549. `groupid` int(19) NOT NULL default '0',
  550. `roleandsubid` varchar(255) NOT NULL default '',
  551. PRIMARY KEY (`groupid`,`roleandsubid`),
  552. CONSTRAINT `fk_group2rs1` FOREIGN KEY (`groupid`) REFERENCES `vtiger_groups` (`groupid`) ON DELETE CASCADE
  553. ) TYPE=InnoDB";
  554. */
  555. Execute($query10);
  556. //Insert all the retrieved old values to the new vtiger_groups table ie., create new vtiger_groups
  557. foreach($group_map_array as $groupname => $description)
  558. {
  559. $empty_array = array(
  560. "groups" => array(""=>""),
  561. "roles" => array(""=>""),
  562. "rs" => array(""=>""),
  563. "users" => array(""=>"")
  564. );
  565. $groupid = createGroup($groupname,$empty_array,$description);
  566. $group_name_id_mapping[$groupname] = $groupid;
  567. }
  568. $conn->println("List of Groups Created (groupname => groupid) ==> ");$conn->println($group_name_id_mapping);
  569. //Copy all mappings in a user2grop table in a array;
  570. //Step 4 : Drop and again create users2group
  571. $query6 = "drop table vtiger_users2group";
  572. Execute($query6);
  573. //Added on 06-06-06
  574. $query7 = "CREATE TABLE vtiger_users2group (
  575. `groupid` int(19) NOT NULL,
  576. `userid` int(19) NOT NULL,
  577. PRIMARY KEY (`groupid`,`userid`),
  578. KEY `users2group_groupname_uerid_idx` (`groupid`,`userid`)
  579. ) ENGINE=InnoDB";
  580. /*
  581. $query7 = "CREATE TABLE vtiger_users2group
  582. (
  583. `groupid` int(19) NOT NULL default '0',
  584. `userid` int(19) NOT NULL default '0',
  585. PRIMARY KEY (`groupid`,`userid`),
  586. CONSTRAINT `fk_users2group1` FOREIGN KEY (`groupid`) REFERENCES `groups` (`groupid`) ON DELETE CASCADE
  587. ) TYPE=InnoDB";
  588. */
  589. Execute($query7);
  590. //Step 5 : put entries to vtiger_users2group table based on vtiger_users2group_map_array. Here get the groupid from vtiger_groups table based on groupname
  591. foreach($users2group_map_array as $userid => $groupname)
  592. {
  593. //$groupid = $conn->query_result($conn->query("select * from vtiger_groups where groupname='".$groupname."'"),0,'groupid');
  594. $sql = "insert into vtiger_users2group (groupid,userid) values(".$group_name_id_mapping[$groupname].",".$userid.")";
  595. Execute($sql);
  596. }
  597. $alter_query_array5 = Array(
  598. "alter table vtiger_leadgrouprelation ADD CONSTRAINT fk_leadgrouprelation2 FOREIGN KEY (groupname) REFERENCES vtiger_groups(groupname) ON DELETE CASCADE",
  599. "ALTER TABLE vtiger_activitygrouprelation ADD CONSTRAINT fk_activitygrouprelation2 FOREIGN KEY (groupname) REFERENCES vtiger_groups(groupname) ON DELETE CASCADE",
  600. "ALTER TABLE vtiger_ticketgrouprelation ADD CONSTRAINT fk_ticketgrouprelation2 FOREIGN KEY (groupname) REFERENCES vtiger_groups(groupname) ON DELETE CASCADE"
  601. );
  602. foreach($alter_query_array5 as $query)
  603. {
  604. Execute($query);
  605. }
  606. //Moved the create table queries for vtiger_group2grouprel, vtiger_group2role, vtiger_group2rs to before creatinf the Group ie., before call the createGroup
  607. /***Added to include decimal places for amount vtiger_field in vtiger_potential table --by Mangai 15-Nov-2005***/
  608. $query11 = "ALTER TABLE vtiger_potential change amount amount decimal(10,2)";
  609. Execute($query11);
  610. /****************** 5.0(Alpha) dev version 2 Database changes -- Ends*********************/
  611. /****************** 5.0(Alpha) dev version 3 Database changes -- Starts*********************/
  612. //Drop the column company_name from vtiger_vendor table ---- modified by Mickie on 18-11-2005
  613. $altersql1 = "alter table vtiger_vendor drop column company_name";
  614. Execute($altersql1);
  615. $altersql2 = "alter table vtiger_vendor change column name vendorname varchar(100) default NULL";
  616. $conn->query($altersql2);
  617. Execute("update vtiger_field set fieldname='vendorname', columnname='vendorname' where tabid=18 and fieldname='name'");
  618. //TODO (check): Remove this company_name entry from the vtiger_field table if it already exists
  619. //Migration for Default Organisation Share -- Added by Don on 20-11-2005
  620. $query1 = "CREATE TABLE vtiger_org_share_action_mapping (
  621. `share_action_id` int(19) NOT NULL default '0',
  622. `share_action_name` varchar(200) NOT NULL default '',
  623. PRIMARY KEY (`share_action_id`,`share_action_name`)
  624. ) TYPE=InnoDB ";
  625. Execute($query1);
  626. $query2 = "CREATE TABLE vtiger_org_share_action2tab (
  627. `share_action_id` int(19) NOT NULL default '0',
  628. `tabid` int(19) NOT NULL default '0',
  629. PRIMARY KEY (`share_action_id`,`tabid`),
  630. CONSTRAINT `fk_org_share_action2tab` FOREIGN KEY (`share_action_id`) REFERENCES `vtiger_org_share_action_mapping` (`share_action_id`) ON DELETE CASCADE
  631. ) TYPE=InnoDB";
  632. Execute($query2);
  633. $query3 = "alter table vtiger_def_org_share add column editstatus int(19)";
  634. Execute($query3);
  635. $query4 = "delete from vtiger_def_org_share where tabid in(8,14,15,18,19)";
  636. Execute($query4);
  637. //Inserting values into org share action mapping
  638. $insert_query_array1 = Array(
  639. "insert into vtiger_org_share_action_mapping values(0,'Public: Read Only')",
  640. "insert into vtiger_org_share_action_mapping values(1,'Public:Read,Create/Edit')",
  641. "insert into vtiger_org_share_action_mapping values(2,'Public: Read, Create/Edit, Delete')",
  642. "insert into vtiger_org_share_action_mapping values(3,'Private')",
  643. "insert into vtiger_org_share_action_mapping values(4,'Hide Details')",
  644. "insert into vtiger_org_share_action_mapping values(5,'Hide Details and Add Events')",
  645. "insert into vtiger_org_share_action_mapping values(6,'Show Details')",
  646. "insert into vtiger_org_share_action_mapping values(7,'Show Details and Add Events')"
  647. );
  648. foreach($insert_query_array1 as $query)
  649. {
  650. Execute($query);
  651. }
  652. //Inserting for all vtiger_tabs
  653. $def_org_tabid=Array(2,4,6,7,9,10,13,16,20,21,22,23,26);
  654. foreach($def_org_tabid as $def_tabid)
  655. {
  656. $insert_query_array2 = Array(
  657. "insert into vtiger_org_share_action2tab values(0,".$def_tabid.")",
  658. "insert into vtiger_org_share_action2tab values(1,".$def_tabid.")",
  659. "insert into vtiger_org_share_action2tab values(2,".$def_tabid.")",
  660. "insert into vtiger_org_share_action2tab values(3,".$def_tabid.")"
  661. );
  662. foreach($insert_query_array2 as $query)
  663. {
  664. Execute($query);
  665. }
  666. }
  667. $insert_query_array3 = Array(
  668. "insert into vtiger_org_share_action2tab values(4,17)",
  669. "insert into vtiger_org_share_action2tab values(5,17)",
  670. "insert into vtiger_org_share_action2tab values(6,17)",
  671. "insert into vtiger_org_share_action2tab values(7,17)"
  672. );
  673. foreach($insert_query_array3 as $query)
  674. {
  675. Execute($query);
  676. }
  677. $query_array1 = Array(
  678. "insert into vtiger_def_org_share values(9,17,7,0)",
  679. "update vtiger_def_org_share set editstatus=0",
  680. "update vtiger_def_org_share set editstatus=2 where tabid=4",
  681. "update vtiger_def_org_share set editstatus=1 where tabid=9",
  682. "update vtiger_def_org_share set editstatus=2 where tabid=16"
  683. );
  684. foreach($query_array1 as $query)
  685. {
  686. Execute($query);
  687. }
  688. /****************** 5.0(Alpha) dev version 3 Database changes -- Ends*********************/
  689. $migrationlog->debug("Database Modifications for 5.0(Alpha) Dev 3 ==> 5.0 Alpha starts here.");
  690. //echo "<br><br><b>Database Modifications for 5.0(Alpha) Dev3 ==> 5.0 Alpha starts here.....</b><br>";
  691. $alter_query_array6 = Array(
  692. "ALTER TABLE vtiger_users ADD column activity_view VARCHAR(25) DEFAULT 'Today' AFTER homeorder",
  693. "ALTER TABLE vtiger_activity ADD column notime VARCHAR(3) NOT NULL DEFAULT '0' AFTER location"
  694. );
  695. foreach($alter_query_array6 as $query)
  696. {
  697. Execute($query);
  698. }
  699. $newfieldid = $conn->getUniqueID("vtiger_field");
  700. $insert_query = "insert into vtiger_field values (9,".$newfieldid.",'notime','activity',1,56,'notime','No Time',1,0,0,100,20,1,3,'C~O',1,'')";
  701. Execute($insert_query);
  702. populateFieldForSecurity('9',$newfieldid);
  703. $newfieldid = $conn->getUniqueID("vtiger_field");
  704. $insert_query = "insert into vtiger_field values (16,".$newfieldid.",'notime','activity',1,56,'notime','No Time',1,0,0,100,18,1,1,'C~O',1,'')";
  705. Execute($insert_query);
  706. populateFieldForSecurity('16',$newfieldid);
  707. $alter_query_array7 = Array(
  708. "alter table vtiger_vendor add column pobox varchar(30) after state",
  709. "alter table vtiger_leadaddress add column pobox varchar(30) after state",
  710. "alter table vtiger_accountbillads add column pobox varchar(30) after state",
  711. "alter table vtiger_accountshipads add column pobox varchar(30) after state",
  712. "alter table vtiger_contactaddress add column mailingpobox varchar(30) after mailingstate",
  713. "alter table vtiger_contactaddress add column otherpobox varchar(30) after otherstate",
  714. "alter table vtiger_quotesbillads add column bill_pobox varchar(30) after bill_street",
  715. "alter table vtiger_quotesshipads add column ship_pobox varchar(30) after ship_street",
  716. "alter table vtiger_pobillads add column bill_pobox varchar(30) after bill_street",
  717. "alter table vtiger_poshipads add column ship_pobox varchar(30) after ship_street",
  718. "alter table vtiger_sobillads add column bill_pobox varchar(30) after bill_street",
  719. "alter table vtiger_soshipads add column ship_pobox varchar(30) after ship_street",
  720. "alter table vtiger_invoicebillads add column bill_pobox varchar(30) after bill_street",
  721. "alter table vtiger_invoiceshipads add column ship_pobox varchar(30) after ship_street"
  722. );
  723. foreach($alter_query_array7 as $query)
  724. {
  725. Execute($query);
  726. }
  727. $newfieldid = $conn->getUniqueID("vtiger_field");
  728. $insert_query = "insert into vtiger_field values (23,".$newfieldid.",'bill_pobox','invoicebillads',1,'1','bill_pobox','Billing Po Box',1,0,0,100,3,2,1,'V~O',1,'')";
  729. Execute($insert_query);
  730. populateFieldForSecurity('23',$newfieldid);
  731. $newfieldid = $conn->getUniqueID("vtiger_field");
  732. $insert_query = "insert into vtiger_field values (23,".$newfieldid.",'ship_pobox','invoiceshipads',1,'1','ship_pobox','Shipping Po Box',1,0,0,100,4,2,1,'V~O',1,'')";
  733. Execute($insert_query);
  734. populateFieldForSecurity('23',$newfieldid);
  735. $newfieldid = $conn->getUniqueID("vtiger_field");
  736. $insert_query = "insert into vtiger_field values (6,".$newfieldid.",'pobox','accountbillads',1,'1','bill_pobox','Billing Po Box',1,0,0,100,3,2,1,'V~O',1,'')";
  737. Execute($insert_query);
  738. populateFieldForSecurity('6',$newfieldid);
  739. $newfieldid = $conn->getUniqueID("vtiger_field");
  740. $insert_query = "insert into vtiger_field values (6,".$newfieldid.",'pobox','accountshipads',1,'1','ship_pobox','Shipping Po Box',1,0,0,100,4,2,1,'V~O',1,'')";
  741. Execute($insert_query);
  742. populateFieldForSecurity('6',$newfieldid);
  743. $newfieldid = $conn->getUniqueID("vtiger_field");
  744. $insert_query = "insert into vtiger_field values (7,".$newfieldid.",'pobox','leadaddress',1,'1','pobox','Po Box',1,0,0,100,2,2,1,'V~O',1,'')";
  745. Execute($insert_query);
  746. populateFieldForSecurity('7',$newfieldid);
  747. $newfieldid = $conn->getUniqueID("vtiger_field");
  748. $insert_query = "insert into vtiger_field values (4,".$newfieldid.",'mailingpobox','contactaddress',1,'1','mailingpobox','Mailing Po Box',1,0,0,100,3,2,1,'V~O',1,'')";
  749. Execute($insert_query);
  750. populateFieldForSecurity('4',$newfieldid);
  751. $newfieldid = $conn->getUniqueID("vtiger_field");
  752. $insert_query = "insert into vtiger_field values (4,".$newfieldid.",'otherpobox','contactaddress',1,'1','otherpobox','Other Po Box',1,0,0,100,4,2,1,'V~O',1,'')";
  753. Execute($insert_query);
  754. populateFieldForSecurity('4',$newfieldid);
  755. $newfieldid = $conn->getUniqueID("vtiger_field");
  756. $insert_query = "insert into vtiger_field values (18,".$newfieldid.",'pobox','vendor',1,'1','pobox','Po Box',1,0,0,100,2,2,1,'V~O',1,'')";
  757. Execute($insert_query);
  758. populateFieldForSecurity('18',$newfieldid);
  759. $newfieldid = $conn->getUniqueID("vtiger_field");
  760. $insert_query = "insert into vtiger_field values (20,".$newfieldid.",'bill_pobox','quotesbillads',1,'1','bill_pobox','Billing Po Box',1,0,0,100,3,2,1,'V~O',1,'')";
  761. Execute($insert_query);
  762. populateFieldForSecurity('20',$newfieldid);
  763. $newfieldid = $conn->getUniqueID("vtiger_field");
  764. $insert_query = "insert into vtiger_field values (20,".$newfieldid.",'ship_pobox','quotesshipads',1,'1','ship_pobox','Shipping Po Box',1,0,0,100,4,2,1,'V~O',1,'')";
  765. Execute($insert_query);
  766. populateFieldForSecurity('20',$newfieldid);
  767. $newfieldid = $conn->getUniqueID("vtiger_field");
  768. $insert_query = "insert into vtiger_field values (21,".$newfieldid.",'bill_pobox','pobillads',1,'1','bill_pobox','Billing Po Box',1,0,0,100,3,2,1,'V~O',1,'')";
  769. Execute($insert_query);
  770. populateFieldForSecurity('21',$newfieldid);
  771. $newfieldid = $conn->getUniqueID("vtiger_field");
  772. $insert_query = "insert into vtiger_field values (21,".$newfieldid.",'ship_pobox','poshipads',1,'1','ship_pobox','Shipping Po Box',1,0,0,100,4,2,1,'V~O',1,'')";
  773. Execute($insert_query);
  774. populateFieldForSecurity('21',$newfieldid);
  775. $newfieldid = $conn->getUniqueID("vtiger_field");
  776. $insert_query = "insert into vtiger_field values (22,".$newfieldid.",'bill_pobox','sobillads',1,'1','bill_pobox','Billing Po Box',1,0,0,100,3,2,1,'V~O',1,'')";
  777. Execute($insert_query);
  778. populateFieldForSecurity('22',$newfieldid);
  779. $newfieldid = $conn->getUniqueID("vtiger_field");
  780. $insert_query = "insert into vtiger_field values (22,".$newfieldid.",'ship_pobox','soshipads',1,'1','ship_pobox','Shipping Po Box',1,0,0,100,4,2,1,'V~O',1,'')";
  781. Execute($insert_query);
  782. populateFieldForSecurity('22',$newfieldid);
  783. $fieldname =array('bill_city','bill_state','bill_code','bill_country','ship_city','ship_state','ship_code','ship_country');
  784. $tablename = array('accountbillads','quotesbillads','pobillads','sobillads','invoicebillads','accountshipads','quotesshipads','poshipads','soshipads','invoiceshipads');
  785. $sequence = array(5,7,9,11,6,8,10,12);
  786. $k = 0;
  787. $n = 0;
  788. for($j = 0;$j < 8;$j++)
  789. {
  790. if($j == 4)
  791. $n = $n+5;
  792. for($i = 0;$i < 5;$i++)
  793. {
  794. $query1 = "update vtiger_field set sequence=".$sequence[$j]." where tablename='".$tablename[$n+$i]."' && fieldname='".$fieldname[$j]."'";
  795. Execute($query1);
  796. }
  797. }
  798. $fieldname = array('code','city','country','state');
  799. $tablename = 'leadaddress';
  800. $sequence = array(3,4,5,6);
  801. for($i = 0;$i < 4;$i++)
  802. {
  803. $query2 = "update vtiger_field set sequence=".$sequence[$i]." where tablename='".$tablename."' && fieldname='".$fieldname[$i]."'";
  804. Execute($query2);
  805. }
  806. $fieldname = array('city','state','postalcode','country');
  807. $tablename = 'vendor';
  808. $sequence = array(3,4,5,6);
  809. for($i = 0;$i < 4;$i++)
  810. {
  811. $query3 = "update vtiger_field set sequence=".$sequence[$i]." where tablename='".$tablename."' && fieldname='".$fieldname[$i]."'";
  812. Execute($query3);
  813. }
  814. $fieldname = array('mailingcity','othercity','mailingstate','otherstate','mailingzip','otherzip','mailingcountry','othercountry');
  815. $tablename = 'contactaddress';
  816. $sequence = array(5,6,7,8,9,10,11,12);
  817. for($i = 0;$i < 8;$i++)
  818. {
  819. $query = "update vtiger_field set sequence=".$sequence[$i]." where tablename='".$tablename."' && fieldname='".$fieldname[$i]."'";
  820. Execute($query);
  821. }
  822. $query_array1 = Array(
  823. "update vtiger_field set tablename='vtiger_crmentity' where tabid=10 and fieldname='description'",
  824. "update vtiger_field set tablename='vtiger_attachments' where tabid=10 and fieldname='filename'",
  825. "drop table vtiger_emails",
  826. "alter table vtiger_activity drop column description",
  827. "update vtiger_field set tablename='vtiger_crmentity' where tabid in (9,16) and fieldname='description'",
  828. "update vtiger_tab set name='PurchaseOrder',tablabel='PurchaseOrder' where tabid=21",
  829. "update vtiger_tab set presence=0 where tabid=22 and name='SalesOrder'",
  830. "delete from vtiger_actionmapping where actionname='SalesOrderDetailView'",
  831. "delete from vtiger_actionmapping where actionname='SalesOrderEditView'",
  832. "delete from vtiger_actionmapping where actionname='SaveSalesOrder'",
  833. "delete from vtiger_actionmapping where actionname='DeleteSalesOrder'",
  834. //"insert into vtiger_field values (13,".$conn->getUniqueID("vtiger_field").",'filename','vtiger_attachments',1,'61','filename','Attachment',1,0,0,100,12,2,1,'V~O',0,1)",
  835. "alter table vtiger_troubletickets add column filename varchar(50) default NULL after title"
  836. );
  837. foreach($query_array1 as $query)
  838. {
  839. Execute($query);
  840. }
  841. $newfieldid = $conn->getUniqueID("vtiger_field");
  842. $insert_query = "insert into vtiger_field values (13,".$newfieldid.",'filename','vtiger_attachments',1,'61','filename','Attachment',1,0,0,100,12,2,1,'V~O',0,1)";
  843. Execute($insert_query);
  844. populateFieldForSecurity('13',$newfieldid);
  845. $create_query3 = "create table vtiger_parenttab(parenttabid int(19) not null, parenttab_label varchar(100) not null, sequence int(10) not null, visible int(2) not null default '0', Primary Key(parenttabid))";
  846. Execute($create_query3);
  847. $create_query4 = "create table vtiger_parenttabrel(parenttabid int(3) not null, tabid int(3) not null,sequence int(3) not null)";
  848. Execute($create_query4);
  849. $insert_query_array4 = Array(
  850. "insert into vtiger_parenttab values(1,'My Home Page',1,0),(2,'Marketing',2,0),(3,'Sales',3,0),(4,'Support',4,0),(5,'Analytics',5,0),(6,'Inventory',6,0), (7,'Tools',7,0),(8,'Settings',8,0)",
  851. "insert into vtiger_parenttabrel values(1,9,2),(1,17,3),(1,10,4),(1,3,1),(3,7,1),(3,6,2),(3,4,3),(3,2,4),(3,20,5),(3,22,6),(3,23,7),(3,14,8),(3,19,9),(3,8,10),(4,13,1),(4,15,2),(4,6,3),(4,4,4),(4,14,5),(4,8,6),(5,1,1),(5,25,2),(6,14,1), (6,18,2), (6,19,3), (6,21,4), (6,22,5), (6,20,6), (6,23,7), (7,24,1), (7,27,2), (7,8,3), (2,6,2), (2,4,3) "
  852. );
  853. foreach($insert_query_array4 as $query)
  854. {
  855. Execute($query);
  856. }
  857. $create_query5 = "CREATE TABLE vtiger_blocks ( blockid int(19) NOT NULL, tabid int(19) NOT NULL, blocklabel varchar(100) NOT NULL, sequence int(19) NOT NULL, show_title int(2) NOT NULL, visible int(2) NOT NULL DEFAULT 0, create_view int(2) NOT NULL DEFAULT 0, edit_view int(2) NOT NULL DEFAULT 0, detail_view int(2) NOT NULL DEFAULT 0, PRIMARY KEY (blockid))";
  858. Execute($create_query5);
  859. $update_query_array1 = Array(
  860. "update vtiger_field set block=2 where tabid=2 and block=5",
  861. "update vtiger_field set block=3 where tabid=2 and block=2",
  862. //"update vtiger_field set block=4 where tabid=4 and block=1",
  863. "update vtiger_field set block=5 where tabid=4 and block=5",
  864. "update vtiger_field set block=6 where tabid=4 and block=4",//Modified on 24-04-06
  865. "update vtiger_field set block=4 where tabid=4 and block=1",
  866. "update vtiger_field set block=7 where tabid=4 and block=2",
  867. "update vtiger_field set block=8 where tabid=4 and block=3",
  868. "update vtiger_field set block=9 where tabid=6 and block=1",
  869. "update vtiger_field set block=10 where tabid=6 and block=5",
  870. "update vtiger_field set block=11 where tabid=6 and block=2",
  871. "update vtiger_field set block=12 where tabid=6 and block=3",
  872. "update vtiger_field set block=13 where tabid=7 and block=1",
  873. "update vtiger_field set block=14 where tabid=7 and block=5",
  874. "update vtiger_field set block=15 where tabid=7 and block=2",
  875. "update vtiger_field set block=16 where tabid=7 and block=3",
  876. "update vtiger_field set block=17 where tabid=8 and block=1",
  877. "update vtiger_field set block=17 where tabid=8 and block=2",
  878. "update vtiger_field set block=18 where tabid=8 and block=3",
  879. "update vtiger_field set block=19 where tabid=9 and block=1",
  880. "update vtiger_field set block=19 where tabid=9 and block=7",
  881. "update vtiger_field set block=20 where tabid=9 and block=2",
  882. "update vtiger_field set block=21 where tabid=10 and block=1",
  883. "update vtiger_field set block=22 where tabid=10 and block=2",
  884. "update vtiger_field set block=23 where tabid=10 and block=3",
  885. "update vtiger_field set block=23 where tabid=10 and block=4",
  886. "update vtiger_field set block=24 where tabid=10 and block=5",
  887. "update vtiger_field set block=25 where tabid=13 and block=1",
  888. "update vtiger_field set block=26 where tabid=13 and block=2",
  889. "update vtiger_field set block=27 where tabid=13 and block=5",
  890. "update vtiger_field set block=28 where tabid=13 and block=3",
  891. "update vtiger_field set block=29 where tabid=13 and block=4",
  892. "update vtiger_field set block=30 where tabid=13 and block=6",
  893. "update vtiger_field set block=31 where tabid=14 and block=1",
  894. "update vtiger_field set block=32 where tabid=14 and block=2",
  895. "update vtiger_field set block=33 where tabid=14 and block=3",
  896. "update vtiger_field set block=34 where tabid=14 and block=5",
  897. "update vtiger_field set block=35 where tabid=14 and block=6",
  898. "update vtiger_field set block=36 where tabid=14 and block=4",
  899. "update vtiger_field set block=37 where tabid=15 and block=1",
  900. "update vtiger_field set block=38 where tabid=15 and block=2",
  901. "update vtiger_field set block=39 where tabid=15 and block=3",
  902. "update vtiger_field set block=40 where tabid=15 and block=4",
  903. "update vtiger_field set block=41 where tabid=16 and block=1",
  904. "update vtiger_field set block=42 where tabid=16 and block=7",
  905. "update vtiger_field set block=43 where tabid=16 and block=2",
  906. "update vtiger_field set block=44 where tabid=18 and block=1",
  907. "update vtiger_field set block=45 where tabid=18 and block=5",
  908. "update vtiger_field set block=36 where tabid=18 and block=2",
  909. "update vtiger_field set block=47 where tabid=18 and block=3",
  910. "update vtiger_field set block=48 where tabid=19 and block=1",
  911. "update vtiger_field set block=49 where tabid=19 and block=5",
  912. "update vtiger_field set block=50 where tabid=19 and block=2",
  913. "update vtiger_field set block=51 where tabid=20 and block=1",
  914. "update vtiger_field set block=52 where tabid=20 and block=5",
  915. "update vtiger_field set block=53 where tabid=20 and block=2",
  916. "update vtiger_field set block=55 where tabid=20 and block=6",
  917. "update vtiger_field set block=56 where tabid=20 and block=3",
  918. "update vtiger_field set block=57 where tabid=21 and block=1",
  919. "update vtiger_field set block=58 where tabid=21 and block=5",
  920. "update vtiger_field set block=59 where tabid=21 and block=2",
  921. "update vtiger_field set block=61 where tabid=21 and block=6",
  922. "update vtiger_field set block=62 where tabid=21 and block=3",
  923. "update vtiger_field set block=63 where tabid=22 and block=1",
  924. "update vtiger_field set block=64 where tabid=22 and block=5",
  925. "update vtiger_field set block=65 where tabid=22 and block=2",
  926. "update vtiger_field set block=67 where tabid=22 and block=6",
  927. "update vtiger_field set block=68 where tabid=22 and block=3",
  928. "update vtiger_field set block=69 where tabid=23 and block=1",
  929. "update vtiger_field set block=70 where tabid=23 and block=5",
  930. "update vtiger_field set block=71 where tabid=23 and block=2",
  931. "update vtiger_field set block=73 where tabid=23 and block=6",
  932. "update vtiger_field set block=74 where tabid=23 and block=3",
  933. );
  934. foreach($update_query_array1 as $query)
  935. {
  936. Execute($query);
  937. }
  938. $insert_query_array5 = Array(
  939. "insert into vtiger_blocks values (1,2,'LBL_OPPORTUNITY_INFORMATION',1,0,0,0,0,0)",
  940. "insert into vtiger_blocks values (2,2,'LBL_CUSTOM_INFORMATION',2,0,0,0,0,0)",
  941. "insert into vtiger_blocks values (3,2,'LBL_DESCRIPTION_INFORMATION',3,0,0,0,0,0)",
  942. "insert into vtiger_blocks values (4,4,'LBL_CONTACT_INFORMATION',1,0,0,0,0,0)",
  943. "insert into vtiger_blocks values (5,4,'LBL_CUSTOM_INFORMATION',2,0,0,0,0,0)",
  944. "insert into vtiger_blocks values (6,4,'LBL_CUSTOMER_PORTAL_INFORMATION',3,0,0,0,0,0)",
  945. "insert into vtiger_blocks values (7,4,'LBL_ADDRESS_INFORMATION',4,0,0,0,0,0)",
  946. "insert into vtiger_blocks values (8,4,'LBL_DESCRIPTION_INFORMATION',5,0,0,0,0,0)",
  947. "insert into vtiger_blocks values (9,6,'LBL_ACCOUNT_INFORMATION',1,0,0,0,0,0)",
  948. "insert into vtiger_blocks values (10,6,'LBL_CUSTOM_INFORMATION',2,0,0,0,0,0)",
  949. "insert into vtiger_blocks values (11,6,'LBL_ADDRESS_INFORMATION',3,0,0,0,0,0)",
  950. "insert into vtiger_blocks values (12,6,'LBL_DESCRIPTION_INFORMATION',4,0,0,0,0,0)",
  951. "insert into vtiger_blocks values (13,7,'LBL_LEAD_INFORMATION',1,0,0,0,0,0)",
  952. "insert into vtiger_blocks values (14,7,'LBL_CUSTOM_INFORMATION',2,0,0,0,0,0)",
  953. "insert into vtiger_blocks values (15,7,'LBL_ADDRESS_INFORMATION',3,0,0,0,0,0)",
  954. "insert into vtiger_blocks values (16,7,'LBL_DESCRIPTION_INFORMATION',4,0,0,0,0,0)",
  955. "insert into vtiger_blocks values (17,8,'LBL_NOTE_INFORMATION',1,0,0,0,0,0)",
  956. "insert into vtiger_blocks values (18,8,'',2,1,0,0,0,0)",
  957. "insert into vtiger_blocks values (19,9,'LBL_TASK_INFORMATION',1,0,0,0,0,0)",
  958. "insert into vtiger_blocks values (20,9,'',2,1,0,0,0,0)",
  959. "insert into vtiger_blocks values (21,10,'LBL_EMAIL_INFORMATION',1,0,0,0,0,0)",
  960. "insert into vtiger_blocks values (22,10,'',2,1,0,0,0,0)",
  961. "insert into vtiger_blocks values (23,10,'',3,1,0,0,0,0)",
  962. "insert into vtiger_blocks values (24,10,'',4,1,0,0,0,0)",
  963. "insert into vtiger_blocks values (25,13,'LBL_TICKET_INFORMATION',1,0,0,0,0,0)",
  964. "insert into vtiger_blocks values (26,13,'',2,1,0,0,0,0)",
  965. "insert into vtiger_blocks values (27,13,'LBL_CUSTOM_INFORMATION',3,0,0,0,0,0)",
  966. "insert into vtiger_blocks values (28,13,'LBL_DESCRIPTION_INFORMATION',4,0,0,0,0,0)",
  967. "insert into vtiger_blocks values (29,13,'LBL_TICKET_RESOLUTION',5,0,0,1,0,0)",
  968. "insert into vtiger_blocks values (30,13,'LBL_COMMENTS',6,0,0,1,0,0)",
  969. "insert into vtiger_blocks values (31,14,'LBL_PRODUCT_INFORMATION',1,0,0,0,0,0)",
  970. "insert into vtiger_blocks values (32,14,'LBL_PRICING_INFORMATION',2,0,0,0,0,0)",
  971. "insert into vtiger_blocks values (33,14,'LBL_STOCK_INFORMATION',3,0,0,0,0,0)",
  972. "insert into vtiger_blocks values (34,14,'LBL_CUSTOM_INFORMATION',4,0,0,0,0,0)",
  973. "insert into vtiger_blocks values (35,14,'LBL_IMAGE_INFORMATION',5,0,0,0,0,0)",
  974. "insert into vtiger_blocks values (36,14,'LBL_DESCRIPTION_INFORMATION',6,0,0,0,0,0)",
  975. "insert into vtiger_blocks values (37,15,'LBL_FAQ_INFORMATION',1,0,0,0,0,0)",
  976. "insert into vtiger_blocks values (38,15,'',2,1,0,0,0,0)",
  977. "insert into vtiger_blocks values (39,15,'',3,1,0,0,0,0)",
  978. "insert into vtiger_blocks values (40,15,'LBL_COMMENT_INFORMATION',4,0,0,1,0,0)",
  979. "insert into vtiger_blocks values (41,16,'LBL_EVENT_INFORMATION',1,0,0,0,0,0)",
  980. "insert into vtiger_blocks values (42,16,'',2,1,0,0,0,0)",
  981. "insert into vtiger_blocks values (43,16,'',3,1,0,0,0,0)",
  982. "insert into vtiger_blocks values (44,18,'LBL_VENDOR_INFORMATION',1,0,0,0,0,0)",
  983. "insert into vtiger_blocks values (45,18,'LBL_CUSTOM_INFORMATION',2,0,0,0,0,0)",
  984. "insert into vtiger_blocks values (46,18,'LBL_VENDOR_ADDRESS_INFORMATION',3,0,0,0,0,0)",
  985. "insert into vtiger_blocks values (47,18,'LBL_DESCRIPTION_INFORMATION',4,0,0,0,0,0)",
  986. "insert into vtiger_blocks values (48,19,'LBL_PRICEBOOK_INFORMATION',1,0,0,0,0,0)",
  987. "insert into vtiger_blocks values (49,19,'LBL_CUSTOM_INFORMATION',2,0,0,0,0,0)",
  988. "insert into vtiger_blocks values (50,19,'LBL_DESCRIPTION_INFORMATION',3,0,0,0,0,0)",
  989. "insert into vtiger_blocks values (51,20,'LBL_QUOTE_INFORMATION',1,0,0,0,0,0)",
  990. "insert into vtiger_blocks values (52,20,'LBL_CUSTOM_INFORMATION',2,0,0,0,0,0)",
  991. "insert into vtiger_blocks values (53,20,'LBL_ADDRESS_INFORMATION',3,0,0,0,0,0)",
  992. "insert into vtiger_blocks values (54,20,'LBL_RELATED_PRODUCTS',4,0,0,0,0,0)",
  993. "insert into vtiger_blocks values (55,20,'LBL_TERMS_INFORMATION',5,0,0,0,0,0)",
  994. "insert into vtiger_blocks values (56,20,'LBL_DESCRIPTION_INFORMATION',6,0,0,0,0,0)",
  995. "insert into vtiger_blocks values (57,21,'LBL_PO_INFORMATION',1,0,0,0,0,0)",
  996. "insert into vtiger_blocks values (58,21,'LBL_CUSTOM_INFORMATION',2,0,0,0,0,0)",
  997. "insert into vtiger_blocks values (59,21,'LBL_ADDRESS_INFORMATION',3,0,0,0,0,0)",
  998. "insert into vtiger_blocks values (60,21,'LBL_RELATED_PRODUCTS',4,0,0,0,0,0)",
  999. "insert into vtiger_blocks values (61,21,'LBL_TERMS_INFORMATION',5,0,0,0,0,0)",
  1000. "insert into vtiger_blocks values (62,21,'LBL_DESCRIPTION_INFORMATION',6,0,0,0,0,0)",
  1001. "insert into vtiger_blocks values (63,22,'LBL_SO_INFORMATION',1,0,0,0,0,0)",
  1002. "insert into vtiger_blocks values (64,22,'LBL_CUSTOM_INFORMATION',2,0,0,0,0,0)",
  1003. "insert into vtiger_blocks values (65,22,'LBL_ADDRESS_INFORMATION',3,0,0,0,0,0)",
  1004. "insert into vtiger_blocks values (66,22,'LBL_RELATED_PRODUCTS',4,0,0,0,0,0)",
  1005. "insert into vtiger_blocks values (67,22,'LBL_TERMS_INFORMATION',5,0,0,0,0,0)",
  1006. "insert into vtiger_blocks values (68,22,'LBL_DESCRIPTION_INFORMATION',6,0,0,0,0,0)",
  1007. "insert into vtiger_blocks values (69,23,'LBL_INVOICE_INFORMATION',1,0,0,0,0,0)",
  1008. "insert into vtiger_blocks values (70,23,'LBL_CUSTOM_INFORMATION',2,0,0,0,0,0)",
  1009. "insert into vtiger_blocks values (71,23,'LBL_ADDRESS_INFORMATION',3,0,0,0,0,0)",
  1010. "insert into vtiger_blocks values (72,23,'LBL_RELATED_PRODUCTS',4,0,0,0,0,0)",
  1011. "insert into vtiger_blocks values (73,23,'LBL_TERMS_INFORMATION',5,0,0,0,0,0)",
  1012. "insert into vtiger_blocks values (74,23,'LBL_DESCRIPTION_INFORMATION',6,0,0,0,0,0)"
  1013. );
  1014. foreach($insert_query_array5 as $query)
  1015. {
  1016. Execute($query);
  1017. }
  1018. $update_query_array2 = Array(
  1019. "update vtiger_tab set name='Vendors', tablabel='Vendors' where tabid=18",
  1020. "update vtiger_tab set name='PriceBooks', tablabel='PriceBooks' where tabid=19",
  1021. "update vtiger_tab set presence=0 where tabid in(18,19)",
  1022. "update vtiger_relatedlists set label='PriceBooks' where tabid=14 and related_tabid=19"
  1023. );
  1024. foreach($update_query_array2 as $query)
  1025. {
  1026. Execute($query);
  1027. }
  1028. $delete_query1 = "delete from vtiger_actionmapping where actionname in ('SavePriceBook','SaveVendor','PriceBookEditView','VendorEditView','DeletePriceBook','DeleteVendor','PriceBookDetailView','VendorDetailView')";
  1029. Execute($delete_query1);
  1030. $insert_query_array6 = Array(
  1031. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'Leads')",
  1032. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'Accounts')",
  1033. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'Contacts')",
  1034. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'Potentials')",
  1035. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'HelpDesk')",
  1036. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'Quotes')",
  1037. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'Activities')",
  1038. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'Emails')",
  1039. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'Invoice')",
  1040. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'Notes')",
  1041. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'PriceBooks')",
  1042. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'Products')",
  1043. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'PurchaseOrder')",
  1044. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'SalesOrder')",
  1045. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'Vendors')",
  1046. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$conn->getUniqueID('vtiger_customview').",'All',1,0,'Faq')"
  1047. );
  1048. foreach($insert_query_array6 as $query)
  1049. {
  1050. Execute($query);
  1051. }
  1052. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='Leads'");
  1053. $cvid = $conn->query_result($res,0,"cvid");
  1054. $insert_query_array7 = Array(
  1055. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_leaddetails:lastname:lastname:Leads_Last_Name:V')",
  1056. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_leaddetails:firstname:firstname:Leads_First_Name:V')",
  1057. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_leaddetails:company:company:Leads_Company:V')",
  1058. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_leadaddress:phone:phone:Leads_Phone:V')",
  1059. "insert into vtiger_cvcolumnlist values ($cvid,4,'vtiger_leadsubdetails:website:website:Leads_Website:V')",
  1060. "insert into vtiger_cvcolumnlist values ($cvid,5,'vtiger_leaddetails:email:email:Leads_Email:V')",
  1061. "insert into vtiger_cvcolumnlist values ($cvid,6,'vtiger_crmentity:smownerid:assigned_user_id:Leads_Assigned_To:V')"
  1062. );
  1063. foreach($insert_query_array7 as $query)
  1064. {
  1065. Execute($query);
  1066. }
  1067. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='Accounts'");
  1068. $cvid = $conn->query_result($res,0,"cvid");
  1069. $insert_query_array8 = Array(
  1070. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_account:accountname:accountname:Accounts_Account_Name:V')",
  1071. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_accountbillads:city:bill_city:Accounts_City:V')",
  1072. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_account:website:website:Accounts_Website:V')",
  1073. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_account:phone:phone:Accounts_Phone:V')",
  1074. "insert into vtiger_cvcolumnlist values ($cvid,4,'vtiger_crmentity:smownerid:assigned_user_id:Accounts_Assigned_To:V')"
  1075. );
  1076. foreach($insert_query_array8 as $query)
  1077. {
  1078. Execute($query);
  1079. }
  1080. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='Contacts'");
  1081. $cvid = $conn->query_result($res,0,"cvid");
  1082. $insert_query_array9 = Array(
  1083. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_contactdetails:firstname:firstname:Contacts_First_Name:V')",
  1084. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_contactdetails:lastname:lastname:Contacts_Last_Name:V')",
  1085. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_contactdetails:title:title:Contacts_Title:V')",
  1086. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_account:accountname:accountname:Contacts_Account_Name:V')",
  1087. "insert into vtiger_cvcolumnlist values ($cvid,4,'vtiger_contactdetails:email:email:Contacts_Email:V')",
  1088. "insert into vtiger_cvcolumnlist values ($cvid,5,'vtiger_contactdetails:phone:phone:Contacts_Office_Phone:V')",
  1089. "insert into vtiger_cvcolumnlist values ($cvid,6,'vtiger_crmentity:smownerid:assigned_user_id:Contacts_Assigned_To:V')"
  1090. );
  1091. foreach($insert_query_array9 as $query)
  1092. {
  1093. Execute($query);
  1094. }
  1095. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='Potentials'");
  1096. $cvid = $conn->query_result($res,0,"cvid");
  1097. $insert_query_array10 = Array(
  1098. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_potential:potentialname:potentialname:Potentials_Potential_Name:V')",
  1099. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_account:accountname:accountname:Potentials_Account_Name:V')",
  1100. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_potential:amount:amount:Potentials_Amount:N')",
  1101. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_potential:closingdate:closingdate:Potentials_Expected_Close_Date:D')",
  1102. "insert into vtiger_cvcolumnlist values ($cvid,4,'vtiger_crmentity:smownerid:assigned_user_id:Potentials_Assigned_To:V')"
  1103. );
  1104. foreach($insert_query_array10 as $query)
  1105. {
  1106. Execute($query);
  1107. }
  1108. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='HelpDesk'");
  1109. $cvid = $conn->query_result($res,0,"cvid");
  1110. $insert_query_array11 = Array(
  1111. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_crmentity:crmid::HelpDesk_Ticket_ID:I')",
  1112. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_troubletickets:title:ticket_title:HelpDesk_Title:V')",
  1113. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_troubletickets:parent_id:parent_id:HelpDesk_Related_to:I')",
  1114. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_troubletickets:status:ticketstatus:HelpDesk_Status:V')",
  1115. "insert into vtiger_cvcolumnlist values ($cvid,4,'vtiger_troubletickets:priority:ticketpriorities:HelpDesk_Priority:V')",
  1116. "insert into vtiger_cvcolumnlist values ($cvid,5,'vtiger_crmentity:smownerid:assigned_user_id:HelpDesk_Assigned_To:V')"
  1117. );
  1118. foreach($insert_query_array11 as $query)
  1119. {
  1120. Execute($query);
  1121. }
  1122. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='Quotes'");
  1123. $cvid = $conn->query_result($res,0,"cvid");
  1124. $insert_query_array12 = Array(
  1125. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_crmentity:crmid::Quotes_Quote_ID:I')",
  1126. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_quotes:subject:subject:Quotes_Subject:V')",
  1127. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_quotes:quotestage:quotestage:Quotes_Quote_Stage:V')",
  1128. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_quotes:potentialid:potential_id:Quotes_Potential_Name:I')",
  1129. "insert into vtiger_cvcolumnlist values ($cvid,4,'vtiger_account:accountname:accountname:Quotes_Account_Name:V')",
  1130. "insert into vtiger_cvcolumnlist values ($cvid,5,'vtiger_quotes:total:hdnGrandTotal:Quotes_Total:I')",
  1131. "insert into vtiger_cvcolumnlist values ($cvid,6,'vtiger_crmentity:smownerid:assigned_user_id:Quotes_Assigned_To:V')"
  1132. );
  1133. foreach($insert_query_array12 as $query)
  1134. {
  1135. Execute($query);
  1136. }
  1137. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='Activities'");
  1138. $cvid = $conn->query_result($res,0,"cvid");
  1139. $insert_query_array13 = Array(
  1140. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_activity:status:taskstatus:Activities_Status:V')",
  1141. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_activity:activitytype:activitytype:Activities_Type:V')",
  1142. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_activity:subject:subject:Activities_Subject:V')",
  1143. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_contactdetails:lastname:lastname:Activities_Contact_Name:V')",
  1144. "insert into vtiger_cvcolumnlist values ($cvid,4,'vtiger_seactivityrel:crmid:parent_id:Activities_Related_To:V')",
  1145. "insert into vtiger_cvcolumnlist values ($cvid,5,'vtiger_activity:date_start:date_start:Activities_Start_Date:D')",
  1146. "insert into vtiger_cvcolumnlist values ($cvid,6,'vtiger_activity:due_date:due_date:Activities_End_Date:D')",
  1147. "insert into vtiger_cvcolumnlist values ($cvid,7,'vtiger_crmentity:smownerid:assigned_user_id:Activities_Assigned_To:V')"
  1148. );
  1149. foreach($insert_query_array13 as $query)
  1150. {
  1151. Execute($query);
  1152. }
  1153. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='Emails'");
  1154. $cvid = $conn->query_result($res,0,"cvid");
  1155. $insert_query_array14 = Array(
  1156. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_activity:subject:subject:Emails_Subject:V')",
  1157. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_seactivityrel:crmid:parent_id:Emails_Related_To:I')",
  1158. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_activity:date_start:date_start:Emails_Date_Sent:D')",
  1159. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_crmentity:smownerid:assigned_user_id:Emails_Assigned_To:V')"
  1160. );
  1161. foreach($insert_query_array14 as $query)
  1162. {
  1163. Execute($query);
  1164. }
  1165. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='Invoice'");
  1166. $cvid = $conn->query_result($res,0,"cvid");
  1167. $insert_query_array15 = Array(
  1168. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_crmentity:crmid::Invoice_Invoice_Id:I')",
  1169. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_invoice:subject:subject:Invoice_Subject:V')",
  1170. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_invoice:salesorderid:salesorder_id:Invoice_Sales_Order:V')",
  1171. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_invoice:invoicestatus:invoicestatus:Invoice_Status:V')",
  1172. "insert into vtiger_cvcolumnlist values ($cvid,4,'vtiger_invoice:total:hdnGrandTotal:Invoice_Total:I')",
  1173. "insert into vtiger_cvcolumnlist values ($cvid,5,'vtiger_crmentity:smownerid:assigned_user_id:Invoice_Assigned_To:V')"
  1174. );
  1175. foreach($insert_query_array15 as $query)
  1176. {
  1177. Execute($query);
  1178. }
  1179. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='Notes'");
  1180. $cvid = $conn->query_result($res,0,"cvid");
  1181. $insert_query_array16 = Array(
  1182. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_notes:title:title:Notes_Title:V')",
  1183. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_notes:contact_id:contact_id:Notes_Contact_Name:I')",
  1184. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_senotesrel:crmid:parent_id:Notes_Related_to:I')",
  1185. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_notes:filename:filename:Notes_File:V')",
  1186. "insert into vtiger_cvcolumnlist values ($cvid,4,'vtiger_crmentity:modifiedtime:modifiedtime:Notes_Modified_Time:V')"
  1187. );
  1188. foreach($insert_query_array16 as $query)
  1189. {
  1190. Execute($query);
  1191. }
  1192. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='PriceBooks'");
  1193. $cvid = $conn->query_result($res,0,"cvid");
  1194. $insert_query_array17 = Array(
  1195. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_pricebook:bookname:bookname:PriceBooks_Price_Book_Name:V')",
  1196. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_pricebook:active:active:PriceBooks_Active:V')"
  1197. );
  1198. foreach($insert_query_array17 as $query)
  1199. {
  1200. Execute($query);
  1201. }
  1202. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='Products'");
  1203. $cvid = $conn->query_result($res,0,"cvid");
  1204. $insert_query_array18 = Array(
  1205. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_products:productname:productname:Products_Product_Name:V')",
  1206. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_products:productcode:productcode:Products_Product_Code:V')",
  1207. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_products:commissionrate:commissionrate:Products_Commission_Rate:V')",
  1208. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_products:qty_per_unit:qty_per_unit:Products_Qty/Unit:V')",
  1209. "insert into vtiger_cvcolumnlist values ($cvid,4,'vtiger_products:unit_price:unit_price:Products_Unit_Price:V')"
  1210. );
  1211. foreach($insert_query_array18 as $query)
  1212. {
  1213. Execute($query);
  1214. }
  1215. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='PurchaseOrder'");
  1216. $cvid = $conn->query_result($res,0,"cvid");
  1217. $insert_query_array19 = Array(
  1218. "insert into vtiger_cvcolumnlist values($cvid,0,'vtiger_crmentity:crmid::PurchaseOrder_Order_Id:I')",
  1219. "insert into vtiger_cvcolumnlist values($cvid,1,'vtiger_purchaseorder:subject:subject:PurchaseOrder_Subject:V')",
  1220. "insert into vtiger_cvcolumnlist values($cvid,2,'vtiger_purchaseorder:vendorid:vendor_id:PurchaseOrder_Vendor_Name:I')",
  1221. "insert into vtiger_cvcolumnlist values($cvid,3,'vtiger_purchaseorder:tracking_no:tracking_no:PurchaseOrder_Tracking_Number:V')",
  1222. "insert into vtiger_cvcolumnlist values($cvid,4,'vtiger_crmentity:smownerid:assigned_user_id:PurchaseOrder_Assigned_To:V')"
  1223. );
  1224. foreach($insert_query_array19 as $query)
  1225. {
  1226. Execute($query);
  1227. }
  1228. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='SalesOrder'");
  1229. $cvid = $conn->query_result($res,0,"cvid");
  1230. $insert_query_array20 = Array(
  1231. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_crmentity:crmid::SalesOrder_Order_Id:I')",
  1232. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_salesorder:subject:subject:SalesOrder_Subject:V')",
  1233. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_account:accountname:accountname:SalesOrder_Account_Name:V')",
  1234. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_quotes:quoteid:quote_id:SalesOrder_Quote_Name:I')",
  1235. "insert into vtiger_cvcolumnlist values ($cvid,4,'vtiger_salesorder:total:hdnGrandTotal:SalesOrder_Total:V')",
  1236. "insert into vtiger_cvcolumnlist values ($cvid,5,'vtiger_crmentity:smownerid:assigned_user_id:SalesOrder_Assigned_To:V')"
  1237. );
  1238. foreach($insert_query_array20 as $query)
  1239. {
  1240. Execute($query);
  1241. }
  1242. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='Vendors'");
  1243. $cvid = $conn->query_result($res,0,"cvid");
  1244. $insert_query_array21 = Array(
  1245. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_vendor:vendorname:vendorname:Vendors_Vendor_Name:V')",
  1246. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_vendor:phone:phone:Vendors_Phone:V')",
  1247. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_vendor:email:email:Vendors_Email:V')",
  1248. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_vendor:category:category:Vendors_Category:V')"
  1249. );
  1250. foreach($insert_query_array21 as $query)
  1251. {
  1252. Execute($query);
  1253. }
  1254. $res=$conn->query("select cvid from vtiger_customview where viewname='All' and entitytype='Faq'");
  1255. $cvid = $conn->query_result($res,0,"cvid");
  1256. $insert_query_array22 = Array(
  1257. "insert into vtiger_cvcolumnlist values ($cvid,0,'vtiger_faq:id::Faq_FAQ_Id:I')",
  1258. "insert into vtiger_cvcolumnlist values ($cvid,1,'vtiger_faq:question:question:Faq_Question:V')",
  1259. "insert into vtiger_cvcolumnlist values ($cvid,2,'vtiger_faq:category:faqcategories:Faq_Category:V')",
  1260. "insert into vtiger_cvcolumnlist values ($cvid,3,'vtiger_faq:product_id:product_id:Faq_Product_Name:I')",
  1261. "insert into vtiger_cvcolumnlist values ($cvid,4,'vtiger_crmentity:createdtime:createdtime:Faq_Created_Time:D')",
  1262. "insert into vtiger_cvcolumnlist values ($cvid,5,'vtiger_crmentity:modifiedtime:modifiedtime:Faq_Modified_Time:D')"
  1263. );
  1264. foreach($insert_query_array22 as $query)
  1265. {
  1266. Execute($query);
  1267. }
  1268. $update_query_array3 = Array(
  1269. "update vtiger_field set uitype=53 where tabid=2 and columnname='smownerid'",
  1270. "update vtiger_field set uitype=53 where tabid=4 and columnname='smownerid'",
  1271. "update vtiger_field set uitype=53 where tabid=20 and columnname='smownerid'",
  1272. "update vtiger_field set uitype=53 where tabid=22 and columnname='smownerid'",
  1273. "update vtiger_field set uitype=53 where tabid=23 and columnname='smownerid'"
  1274. );
  1275. foreach($update_query_array3 as $query)
  1276. {
  1277. Execute($query);
  1278. }
  1279. //Added on 26-06-06 - we cannot add foreign key in type MyISAM, so we have to change the type to InnoDB
  1280. $alter_tables_array = Array("vtiger_groups","vtiger_potential","vtiger_quotes","vtiger_salesorder","vtiger_invoice","vtiger_purchaseorder","vtiger_products","vtiger_account","vtiger_contactdetails","vtiger_vendor","vtiger_users","vtiger_attachments","vtiger_profile");
  1281. foreach($alter_tables_array as $tablename)
  1282. {
  1283. Execute("alter table $tablename type=InnoDB");
  1284. }
  1285. $create_query6 = "CREATE TABLE vtiger_accountgrouprelation ( accountid int(19) NOT NULL, groupname varchar(100) default NULL, PRIMARY KEY (`accountid`)) ENGINE=InnoDB";
  1286. Execute($create_query6);
  1287. $alter_query_array8 = Array(
  1288. "alter table vtiger_accountgrouprelation ADD CONSTRAINT fk_1_vtiger_accountgrouprelation FOREIGN KEY (accountid) REFERENCES vtiger_account(accountid) ON DELETE CASCADE",
  1289. "alter table vtiger_accountgrouprelation ADD CONSTRAINT fk_2_vtiger_accountgrouprelation FOREIGN KEY (groupname) REFERENCES vtiger_groups(groupname) ON DELETE CASCADE",
  1290. "ALTER TABLE `vtiger_accountgrouprelation` ADD KEY accountgrouprelation_groupname_idx (groupname)",
  1291. );
  1292. foreach($alter_query_array8 as $query)
  1293. {
  1294. Execute($query);
  1295. }
  1296. $create_query7 = "CREATE TABLE vtiger_contactgrouprelation ( contactid int(19) NOT NULL default '0', groupname varchar(100) default NULL, PRIMARY KEY (`contactid`))";
  1297. Execute($create_query7);
  1298. $alter_query_array9 = Array(
  1299. "alter table vtiger_contactgrouprelation ADD CONSTRAINT fk_contactgrouprelation FOREIGN KEY (contactid) REFERENCES vtiger_contactdetails(contactid) ON DELETE CASCADE",
  1300. "alter table vtiger_contactgrouprelation ADD CONSTRAINT fk_contactgrouprelation2 FOREIGN KEY (groupname) REFERENCES vtiger_groups(groupname) ON DELETE CASCADE"
  1301. );
  1302. foreach($alter_query_array9 as $query)
  1303. {
  1304. Execute($query);
  1305. }
  1306. $create_query10 = "CREATE TABLE vtiger_potentialgrouprelation ( potentialid int(19) NOT NULL default '0', groupname varchar(100) default NULL, PRIMARY KEY (`potentialid`))";
  1307. Execute($create_query10);
  1308. $alter_query_array10 = Array(
  1309. "alter table vtiger_potentialgrouprelation ADD CONSTRAINT fk_potentialgrouprelation FOREIGN KEY (potentialid) REFERENCES vtiger_potential(potentialid) ON DELETE CASCADE",
  1310. "alter table vtiger_potentialgrouprelation ADD CONSTRAINT fk_potentialgrouprelation2 FOREIGN KEY (groupname) REFERENCES vtiger_groups(groupname) ON DELETE CASCADE"
  1311. );
  1312. foreach($alter_query_array10 as $query)
  1313. {
  1314. Execute($query);
  1315. }
  1316. $create_query11 = "CREATE TABLE vtiger_quotegrouprelation ( quoteid int(19) NOT NULL default '0', groupname varchar(100) default NULL, PRIMARY KEY (`quoteid`) )";
  1317. Execute($create_query11);
  1318. $alter_query_array11 = Array(
  1319. "alter table vtiger_quotegrouprelation ADD CONSTRAINT fk_quotegrouprelation FOREIGN KEY (quoteid) REFERENCES vtiger_quotes(quoteid) ON DELETE CASCADE",
  1320. "alter table vtiger_quotegrouprelation ADD CONSTRAINT fk_quotegrouprelation2 FOREIGN KEY (groupname) REFERENCES vtiger_groups(groupname) ON DELETE CASCADE"
  1321. );
  1322. foreach($alter_query_array11 as $query)
  1323. {
  1324. Execute($query);
  1325. }
  1326. $create_query12 = "CREATE TABLE vtiger_sogrouprelation ( salesorderid int(19) NOT NULL default '0', groupname varchar(100) default NULL, PRIMARY KEY (`salesorderid`) )";
  1327. Execute($create_query12);
  1328. $alter_query_array12 = Array(
  1329. "alter table vtiger_sogrouprelation ADD CONSTRAINT fk_sogrouprelation FOREIGN KEY (salesorderid) REFERENCES vtiger_salesorder(salesorderid) ON DELETE CASCADE",
  1330. "alter table vtiger_sogrouprelation ADD CONSTRAINT fk_sogrouprelation2 FOREIGN KEY (groupname) REFERENCES vtiger_groups(groupname) ON DELETE CASCADE"
  1331. );
  1332. foreach($alter_query_array12 as $query)
  1333. {
  1334. Execute($query);
  1335. }
  1336. $create_query13 = "CREATE TABLE vtiger_invoicegrouprelation ( invoiceid int(19) NOT NULL default '0', groupname varchar(100) default NULL, PRIMARY KEY (`invoiceid`))";
  1337. Execute($create_query13);
  1338. $alter_query_array13 = Array(
  1339. "alter table vtiger_invoicegrouprelation ADD CONSTRAINT fk_invoicegrouprelation FOREIGN KEY (invoiceid) REFERENCES vtiger_invoice(invoiceid) ON DELETE CASCADE",
  1340. "alter table vtiger_invoicegrouprelation ADD CONSTRAINT fk_invoicegrouprelation2 FOREIGN KEY (groupname) REFERENCES vtiger_groups(groupname) ON DELETE CASCADE"
  1341. );
  1342. foreach($alter_query_array13 as $query)
  1343. {
  1344. Execute($query);
  1345. }
  1346. $create_query14 = "CREATE TABLE vtiger_pogrouprelation ( purchaseorderid int(19) NOT NULL default '0', groupname varchar(100) default NULL, PRIMARY KEY (`purchaseorderid`))";
  1347. Execute($create_query14);
  1348. $alter_query_array14 = Array(
  1349. "alter table vtiger_pogrouprelation ADD CONSTRAINT fk_pogrouprelation FOREIGN KEY (purchaseorderid) REFERENCES vtiger_purchaseorder(purchaseorderid) ON DELETE CASCADE",
  1350. "alter table vtiger_pogrouprelation ADD CONSTRAINT fk_productgrouprelation2 FOREIGN KEY (groupname) REFERENCES vtiger_groups(groupname) ON DELETE CASCADE"
  1351. );
  1352. foreach($alter_query_array14 as $query)
  1353. {
  1354. Execute($query);
  1355. }
  1356. $alter_query1 = "ALTER TABLE vtiger_users ADD column lead_view VARCHAR(25) DEFAULT 'Today' AFTER homeorder";
  1357. Execute($alter_query1);
  1358. $update_query1 = "update vtiger_users set homeorder = 'ALVT,PLVT,QLTQ,CVLVT,HLT,OLV,GRT,OLTSO,ILTI,MNL'";
  1359. Execute($update_query1);
  1360. $alter_query2 = "ALTER TABLE vtiger_products change column imagename imagename text";
  1361. Execute($alter_query2);
  1362. $alter_query3 = "alter table vtiger_systems modify server varchar(50), modify server_username varchar(50), modify server_password varchar(50), add column smtp_auth char(5)";
  1363. Execute($alter_query3);
  1364. $alter_query_array15 = Array(
  1365. "alter table vtiger_users add column imagename varchar(250)",
  1366. "alter table vtiger_users add column tagcloud varchar(250)"
  1367. );
  1368. foreach($alter_query_array15 as $query)
  1369. {
  1370. Execute($query);
  1371. }
  1372. $alter_query_array16 = Array(
  1373. "alter table vtiger_systems change column server server varchar(80) default NULL",
  1374. "alter table vtiger_systems change column server_username server_username varchar(80) default NULL"
  1375. );
  1376. foreach($alter_query_array16 as $query)
  1377. {
  1378. Execute($query);
  1379. }
  1380. $create_query15 = "create table vtiger_portal(portalid int(19), portalname varchar(255) NOT NULL, portalurl varchar(255) NOT NULL,sequence int(3) NOT NULL, PRIMARY KEY (portalid))";
  1381. Execute($create_query15);
  1382. $alter_query = "ALTER TABLE vtiger_field ADD column info_type varchar(20) default NULL after quickcreatesequence";
  1383. Execute($alter_query);
  1384. //$update_query2 = "UPDATE vtiger_field SET fieldlabel = 'Reference' WHERE tabid = 4 and tablename = 'contactdetails' and fieldname='reference'";
  1385. //changed in 24-04-06 because the reference has not been entered into the vtiger_field table.
  1386. $newfieldid = $conn->getUniqueID("vtiger_field");
  1387. $update_query2 = "insert into vtiger_field values (4,".$newfieldid.",'reference','contactdetails',1,'56','reference','Reference',1,0,0,10,23,4,1,'C~O',1,null,'ADV')";
  1388. Execute($update_query2);
  1389. populateFieldForSecurity('4',$newfieldid);
  1390. $update_query_array4 = Array(
  1391. "UPDATE vtiger_field SET info_type = 'BAS'",
  1392. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 7 and fieldlabel = 'Website'",
  1393. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 7 and fieldlabel = 'Industry'",
  1394. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 7 and fieldlabel = 'Annual Revenue'",
  1395. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 7 and fieldlabel = 'No Of Employees'",
  1396. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 7 and fieldlabel = 'Yahoo Id'",
  1397. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 6 and fieldlabel = 'Ticker Symbol'",
  1398. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 6 and fieldlabel = 'Other Phone'",
  1399. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 6 and fieldlabel = 'Member Of'",
  1400. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 6 and fieldlabel = 'Employees'",
  1401. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 6 and fieldlabel = 'Other Email'",
  1402. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 6 and fieldlabel = 'Ownership'",
  1403. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 6 and fieldlabel = 'Rating'",
  1404. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 6 and fieldlabel = 'industry'",
  1405. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 6 and fieldlabel = 'SIC Code'",
  1406. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 6 and fieldlabel = 'Type'",
  1407. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 6 and fieldlabel = 'Annual Revenue'",
  1408. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 6 and fieldlabel = 'Email Opt Out'",
  1409. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Home Phone'",
  1410. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Department'",
  1411. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Birthdate'",
  1412. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Email'",
  1413. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Reports To'",
  1414. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Assistant'",
  1415. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Yahoo Id'",
  1416. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Assistant Phone'",
  1417. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Do Not Call'",
  1418. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Email Opt Out'",
  1419. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Reference'",
  1420. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Portal User'",
  1421. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Support Start Date'",
  1422. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Support End Date'",
  1423. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 4 and fieldlabel = 'Contact Image'",
  1424. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 14 and fieldlabel = 'Usage Unit'",
  1425. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 14 and fieldlabel = 'Qty/Unit'",
  1426. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 14 and fieldlabel = 'Qty In Stock'",
  1427. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 14 and fieldlabel = 'Reorder Level'",
  1428. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 14 and fieldlabel = 'Handler'",
  1429. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 14 and fieldlabel = 'Qty In Demand'",
  1430. "UPDATE vtiger_field SET info_type = 'ADV' WHERE tabid = 14 and fieldlabel = 'Product Image'"
  1431. );
  1432. foreach($update_query_array4 as $query)
  1433. {
  1434. Execute($query);
  1435. }
  1436. $create_query16 = "CREATE TABLE vtiger_chat_msg ( `id` bigint(20) NOT NULL auto_increment, `chat_from` bigint(20) NOT NULL default '0', `chat_to` bigint(20) NOT NULL default '0', `born` timestamp NULL default '0000-00-00 00:00:00', `msg` varchar(255) NOT NULL, PRIMARY KEY (`id`), KEY `chat_to` (`chat_to`), KEY `chat_from` (`chat_from`), KEY `born` (`born`)) ENGINE=InnoDB";
  1437. Execute($create_query16);
  1438. $create_query17 = "CREATE TABLE vtiger_chat_pchat ( `id` bigint(20) NOT NULL auto_increment, `msg` bigint(20) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `msg` (`msg`)) ENGINE=InnoDB";
  1439. Execute($create_query17);
  1440. $create_query18 = "CREATE TABLE vtiger_chat_pvchat ( `id` bigint(20) NOT NULL auto_increment, `msg` bigint(20) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `msg` (`msg`)) ENGINE=InnoDB";
  1441. Execute($create_query18);
  1442. $create_query19 = "CREATE TABLE vtiger_chat_users ( `id` bigint(20) NOT NULL auto_increment, `nick` varchar(50) NOT NULL, `session` varchar(50) NOT NULL, `ip` varchar(20) NOT NULL default '000.000.000.000', `ping` timestamp NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`), UNIQUE KEY `session` (`session`), UNIQUE KEY `nick` (`nick`), KEY `ping` (`ping`)) ENGINE=InnoDB";
  1443. Execute($create_query19);
  1444. $alter_query_array17 = Array(
  1445. "ALTER TABLE `vtiger_chat_msg` ADD CONSTRAINT `chat_msg_ibfk_1` FOREIGN KEY (`chat_from`) REFERENCES `vtiger_chat_users` (`id`) ON DELETE CASCADE",
  1446. "ALTER TABLE `vtiger_chat_pchat` ADD CONSTRAINT `chat_pchat_ibfk_1` FOREIGN KEY (`msg`) REFERENCES `vtiger_chat_msg` (`id`) ON DELETE CASCADE",
  1447. "ALTER TABLE `vtiger_chat_pvchat` ADD CONSTRAINT `chat_pvchat_ibfk_1` FOREIGN KEY (`msg`) REFERENCES `vtiger_chat_msg` (`id`) ON DELETE CASCADE"
  1448. );
  1449. foreach($alter_query_array17 as $query)
  1450. {
  1451. Execute($query);
  1452. }
  1453. $create_query20 = "CREATE TABLE vtiger_freetags ( id int(19) NOT NULL, tag varchar(50) NOT NULL default '', raw_tag varchar(50) NOT NULL default '', PRIMARY KEY (id)) TYPE=InnoDB";
  1454. Execute($create_query20);
  1455. $create_query21 = "CREATE TABLE vtiger_freetagged_objects ( tag_id int(20) NOT NULL default '0', tagger_id int(20) NOT NULL default '0', object_id int(20) NOT NULL default '0', tagged_on timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, module varchar(50) NOT NULL default '', PRIMARY KEY (`tag_id`,`tagger_id`,`object_id`), KEY `freetagged_objects_tag_id_tagger_id_object_id_idx` (`tag_id`,`tagger_id`,`object_id`)) TYPE=InnoDB";
  1456. Execute($create_query21);
  1457. $alter_query4 = "alter table vtiger_profile add column description text";
  1458. Execute($alter_query4);
  1459. $alter_query5 = "alter table vtiger_contactdetails add column imagename varchar(250) after currency";
  1460. Execute($alter_query5);
  1461. $alter_query = "ALTER TABLE vtiger_contactdetails ADD column reference varchar(3) default NULL after imagename";
  1462. Execute($alter_query);
  1463. Execute("insert into vtiger_blocks values(75,4,'LBL_IMAGE_INFORMATION',5,0,0,0,0,0)");
  1464. $newfieldid = $conn->getUniqueID("vtiger_field");
  1465. $insert_query = "insert into vtiger_field values (4,".$newfieldid.",'imagename','contactdetails',1,'69','imagename','Contact Image',1,0,0,100,1,75,1,'V~O',1,null,'ADV')";
  1466. Execute($insert_query);
  1467. populateFieldForSecurity('4',$newfieldid);
  1468. $newfieldid = $conn->getUniqueID("vtiger_field");
  1469. $insert_query = "insert into vtiger_field values (9,".$newfieldid.",'visibility','activity',1,15,'visibility','Visibility',1,0,0,100,17,19,3,'V~O',1,null,'BAS')";
  1470. Execute($insert_query);
  1471. populateFieldForSecurity('9',$newfieldid);
  1472. $newfieldid = $conn->getUniqueID("vtiger_field");
  1473. $insert_query = "insert into vtiger_field values (16,".$newfieldid.",'visibility','activity',1,15,'visibility','Visibility',1,0,0,100,19,41,1,'V~O',1,null,'BAS')";
  1474. Execute($insert_query);
  1475. populateFieldForSecurity('16',$newfieldid);
  1476. $alter_query6 = "ALTER TABLE vtiger_activity ADD COLUMN visibility varchar(50) NOT NULL DEFAULT 'all' after notime";
  1477. Execute($alter_query6);
  1478. $create_query22 = "CREATE TABLE vtiger_visibility ( `visibilityid` int(19) NOT NULL auto_increment, `visibility` varchar(200) NOT NULL default '', `sortorderid` int(19) NOT NULL default '0', `presence` int(1) NOT NULL default '1', PRIMARY KEY (`visibilityid`), UNIQUE KEY `Visibility_VLY` (`visibility`)) ENGINE=InnoDB";
  1479. Execute($create_query22);
  1480. $create_query23 = "CREATE TABLE vtiger_sharedcalendar ( `userid` int(19) NOT NULL default '0', `sharedid` int(19) NOT NULL default '0', PRIMARY KEY (`userid`,`sharedid`)) ENGINE=InnoDB";
  1481. Execute($create_query23);
  1482. $insert_query6 = "INSERT INTO vtiger_tab VALUES(26,'Campaigns',0,23,'Campaigns',null,null,1)";
  1483. Execute($insert_query6);
  1484. $insert_query7 = "INSERT INTO vtiger_parenttabrel VALUES(2,26,1)";
  1485. Execute($insert_query7);
  1486. $insert_query8 = "insert into vtiger_blocks values(76,26,'LBL_CAMPAIGN_INFORMATION',1,0,0,0,0,0)";
  1487. Execute($insert_query8);
  1488. $insert_query8 = "insert into vtiger_blocks values (77,26,'LBL_CUSTOM_INFORMATION',2,0,0,0,0,0)";
  1489. Execute($insert_query8);
  1490. $insert_query9 = "insert into vtiger_blocks values(78,26,'LBL_DESCRIPTION_INFORMATION',3,0,0,0,0,0)";
  1491. Execute($insert_query9);
  1492. $newfieldid = $conn->getUniqueID("vtiger_field");
  1493. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'campaignname','campaign',1,'2','campaignname','Campaign Name',1,0,0,100,1,76,1,'V~M',0,1,'BAS')";
  1494. Execute($insert_query);
  1495. populateFieldForSecurity('26',$newfieldid);
  1496. $newfieldid = $conn->getUniqueID("vtiger_field");
  1497. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'campaigntype','campaign',1,15,'campaigntype','Campaign Type',1,0,0,100,2,76,1,'V~O',0,5,'BAS')";
  1498. Execute($insert_query);
  1499. populateFieldForSecurity('26',$newfieldid);
  1500. $newfieldid = $conn->getUniqueID("vtiger_field");
  1501. $insert_query = "insert into vtiger_field values (26, $newfieldid,'product_id','campaign',1,59,'product_id','Product',1,0,0,100,3,76,1,'I~O',0,5,'BAS')";
  1502. Execute($insert_query);
  1503. populateFieldForSecurity('26',$newfieldid);
  1504. $newfieldid = $conn->getUniqueID("vtiger_field");
  1505. $insert_query = "insert into vtiger_field values (26, $newfieldid,'campaignstatus','campaign',1,15,'campaignstatus','Campaign Status',1,0,0,100,4,76,1,'V~O',0,5,'BAS')";
  1506. Execute($insert_query);
  1507. populateFieldForSecurity('26',$newfieldid);
  1508. $newfieldid = $conn->getUniqueID("vtiger_field");
  1509. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'closingdate','campaign',1,'23','closingdate','Expected Close Date',1,0,0,100,5,76,1,'D~M',0,3,'BAS')";
  1510. Execute($insert_query);
  1511. populateFieldForSecurity('26',$newfieldid);
  1512. $newfieldid = $conn->getUniqueID("vtiger_field");
  1513. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'expectedrevenue','campaign',1,'1','expectedrevenue','Expected Revenue',1,0,0,100,6,76,1,'I~O',1,null,'BAS')";
  1514. Execute($insert_query);
  1515. populateFieldForSecurity('26',$newfieldid);
  1516. $newfieldid = $conn->getUniqueID("vtiger_field");
  1517. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'budgetcost','campaign',1,'1','budgetcost','Budget Cost',1,0,0,100,7,76,1,'I~O',1,null,'BAS')";
  1518. Execute($insert_query);
  1519. populateFieldForSecurity('26',$newfieldid);
  1520. $newfieldid = $conn->getUniqueID("vtiger_field");
  1521. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'actualcost','campaign',1,'1','actualcost','Actual Cost',1,0,0,100,8,76,1,'I~O',1,null,'BAS')";
  1522. Execute($insert_query);
  1523. populateFieldForSecurity('26',$newfieldid);
  1524. $newfieldid = $conn->getUniqueID("vtiger_field");
  1525. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'expectedresponse','campaign',1,'15','expectedresponse','Expected Response',1,0,0,100,9,76,1,'V~O',0,4,'BAS')";
  1526. Execute($insert_query);
  1527. populateFieldForSecurity('26',$newfieldid);
  1528. $newfieldid = $conn->getUniqueID("vtiger_field");
  1529. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'smownerid','crmentity',1,'53','assigned_user_id','Assigned To',1,0,0,100,10,76,1,'V~M',1,null,'BAS')";
  1530. Execute($insert_query);
  1531. populateFieldForSecurity('26',$newfieldid);
  1532. $newfieldid = $conn->getUniqueID("vtiger_field");
  1533. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'numsent','campaign',1,'9','numsent','Num Sent',1,0,0,100,11,76,1,'N~O',1,null,'BAS')";
  1534. Execute($insert_query);
  1535. populateFieldForSecurity('26',$newfieldid);
  1536. $newfieldid = $conn->getUniqueID("vtiger_field");
  1537. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'sponsor','campaign',1,'1','sponsor','Sponsor',1,0,0,100,12,76,1,'V~O',1,null,'BAS')";
  1538. Execute($insert_query);
  1539. populateFieldForSecurity('26',$newfieldid);
  1540. $newfieldid = $conn->getUniqueID("vtiger_field");
  1541. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'targetaudience','campaign',1,'1','targetaudience','Target Audience',1,0,0,100,13,76,1,'V~O',1,null,'BAS')";
  1542. Execute($insert_query);
  1543. populateFieldForSecurity('26',$newfieldid);
  1544. $newfieldid = $conn->getUniqueID("vtiger_field");
  1545. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'targetsize','campaign',1,'1','targetsize','TargetSize',1,0,0,100,14,76,1,'N~O',1,null,'BAS')";
  1546. Execute($insert_query);
  1547. populateFieldForSecurity('26',$newfieldid);
  1548. $newfieldid = $conn->getUniqueID("vtiger_field");
  1549. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'expectedresponsecount','campaign',1,'1','expectedresponsecount','Expected Response Count',1,0,0,100,17,76,1,'N~O',1,null,'BAS')";
  1550. Execute($insert_query);
  1551. populateFieldForSecurity('26',$newfieldid);
  1552. $newfieldid = $conn->getUniqueID("vtiger_field");
  1553. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'expectedsalescount','campaign',1,'1','expectedsalescount','Expected Sales Count',1,0,0,100,15,76,1,'N~O',1,null,'BAS')";
  1554. Execute($insert_query);
  1555. populateFieldForSecurity('26',$newfieldid);
  1556. $newfieldid = $conn->getUniqueID("vtiger_field");
  1557. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'expectedroi','campaign',1,'1','expectedroi','Expected ROI',1,0,0,100,19,76,1,'N~O',1,null,'BAS')";
  1558. Execute($insert_query);
  1559. populateFieldForSecurity('26',$newfieldid);
  1560. $newfieldid = $conn->getUniqueID("vtiger_field");
  1561. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'actualresponsecount','campaign',1,'1','actualresponsecount','Actual Response Count',1,0,0,100,18,76,1,'N~O',1,null,'BAS')";
  1562. Execute($insert_query);
  1563. populateFieldForSecurity('26',$newfieldid);
  1564. $newfieldid = $conn->getUniqueID("vtiger_field");
  1565. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'actualsalescount','campaign',1,'1','actualsalescount','Actual Sales Count',1,0,0,100,16,76,1,'N~O',1,null,'BAS')";
  1566. Execute($insert_query);
  1567. populateFieldForSecurity('26',$newfieldid);
  1568. $newfieldid = $conn->getUniqueID("vtiger_field");
  1569. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'actualroi','campaign',1,'1','actualroi','Actual ROI',1,0,0,100,20,76,1,'N~O',1,null,'BAS')";
  1570. Execute($insert_query);
  1571. populateFieldForSecurity('26',$newfieldid);
  1572. $newfieldid = $conn->getUniqueID("vtiger_field");
  1573. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'createdtime','crmentity',1,'70','createdtime','Created Time',1,0,0,100,15,76,2,'T~O',1,null,'BAS')";
  1574. Execute($insert_query);
  1575. populateFieldForSecurity('26',$newfieldid);
  1576. $newfieldid = $conn->getUniqueID("vtiger_field");
  1577. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'modifiedtime','crmentity',1,'70','modifiedtime','Modified Time',1,0,0,100,16,76,2,'T~O',1,null,'BAS')";
  1578. Execute($insert_query);
  1579. populateFieldForSecurity('26',$newfieldid);
  1580. $newfieldid = $conn->getUniqueID("vtiger_field");
  1581. $insert_query = "insert into vtiger_field values (26, $newfieldid, 'description','crmentity',1,'19','description','Description',1,0,0,100,1,82,1,'V~O',1,null,'BAS')";
  1582. Execute($insert_query);
  1583. populateFieldForSecurity('26',$newfieldid);
  1584. /*
  1585. //add all field entries to def_org_field and profile2field tables for Campaigns
  1586. $field_res = $conn->query("select fieldid from vtiger_field where tabid=26");
  1587. for($i=0;$i<$conn->num_rows($field_res);$i++)
  1588. {
  1589. $fieldid = $conn->query_result($field_res,$i,'fieldid');
  1590. populateFieldForSecurity('26',$fieldid);
  1591. }
  1592. */
  1593. $insert_query_array25 = Array(
  1594. "insert into vtiger_relatedlists values (".$conn->getUniqueID('vtiger_relatedlists').",".getTabid("Campaigns").",".getTabid("Contacts").",'get_contacts',1,'Contacts',0)",
  1595. "insert into vtiger_relatedlists values (".$conn->getUniqueID('vtiger_relatedlists').",".getTabid("Campaigns").",".getTabid("Leads").",'get_leads',2,'Leads',0)"
  1596. );
  1597. foreach($insert_query_array25 as $query)
  1598. {
  1599. Execute($query);
  1600. }
  1601. $newfieldid = $conn->getUniqueID("vtiger_field");
  1602. $insert_query = "insert into vtiger_field values (7, $newfieldid, 'campaignid','leaddetails',1,'51','campaignid','Campaign Name',1,0,0,100,6,13,3,'I~O',1,null,'BAS')";
  1603. Execute($insert_query);
  1604. populateFieldForSecurity('7',$newfieldid);
  1605. $newfieldid = $conn->getUniqueID("vtiger_field");
  1606. $insert_query = "insert into vtiger_field values (4, $newfieldid, 'campaignid','contactdetails',1,'51','campaignid','Campaign Name',1,0,0,100,6,4,3,'I~O',1,null,'BAS')";
  1607. Execute($insert_query);
  1608. populateFieldForSecurity('4',$newfieldid);
  1609. $create_query24 = "
  1610. CREATE TABLE vtiger_campaign (
  1611. `campaignname` varchar(255) default NULL,
  1612. `campaigntype` varchar(255) default NULL,
  1613. `campaignstatus` varchar(255) default NULL,
  1614. `expectedrevenue` int(19) default NULL,
  1615. `budgetcost` int(19) default NULL,
  1616. `actualcost` int(19) default NULL,
  1617. `expectedresponse` varchar(255) default NULL,
  1618. `numsent` decimal(11,0) default NULL,
  1619. `product_id` int(19) default NULL,
  1620. `sponsor` varchar(255) default NULL,
  1621. `targetaudience` varchar(255) default NULL,
  1622. `targetsize` int(19) default NULL,
  1623. `expectedresponsecount` int(19) default NULL,
  1624. `expectedsalescount` int(19) default NULL,
  1625. `expectedroi` int(19) default NULL,
  1626. `actualresponsecount` int(19) default NULL,
  1627. `actualsalescount` int(19) default NULL,
  1628. `actualroi` int(19) default NULL,
  1629. `campaignid` int(19) NOT NULL,
  1630. `closingdate` date default NULL,
  1631. PRIMARY KEY (`campaignid`),
  1632. KEY `idx_campaignstatus` (`campaignstatus`),
  1633. KEY `idx_campaignname` (`campaignname`),
  1634. KEY `idx_campaignid` (`campaignid`)
  1635. ) ENGINE=InnoDB
  1636. ";
  1637. Execute($create_query24);
  1638. //Added on 06-06-06
  1639. $create_query25 = "CREATE TABLE vtiger_campaigncontrel (
  1640. `campaignid` int(19) NOT NULL default '0',
  1641. `contactid` int(19) NOT NULL default '0',
  1642. PRIMARY KEY (`campaignid`),
  1643. KEY `campaigncontrel_contractid_idx` (`contactid`)
  1644. ) ENGINE=InnoDB";
  1645. /*
  1646. $create_query25 = "CREATE TABLE vtiger_campaigncontrel (
  1647. `campaignid` int(19) NOT NULL default '0',
  1648. `contactid` int(19) NOT NULL default '0',
  1649. PRIMARY KEY (`campaignid`),
  1650. KEY `CampaignContRel_IDX1` (`contactid`),
  1651. CONSTRAINT `fk_CampaignContRel2` FOREIGN KEY (`contactid`) REFERENCES `vtiger_contactdetails` (`contactid`) ON DELETE CASCADE,
  1652. CONSTRAINT `fk_CampaignContRel1` FOREIGN KEY (`campaignid`) REFERENCES `vtiger_campaign` (`campaignid`) ON DELETE CASCADE
  1653. ) ENGINE=InnoDB";
  1654. */
  1655. Execute($create_query25);
  1656. //Added on 06-06-06
  1657. $create_table_query = "CREATE TABLE vtiger_campaigngrouprelation (
  1658. `campaignid` int(19) NOT NULL,
  1659. `groupname` varchar(100) default NULL,
  1660. PRIMARY KEY (`campaignid`),
  1661. KEY `campaigngrouprelation_IDX1` (`groupname`)
  1662. ) ENGINE=InnoDB";
  1663. /*
  1664. $create_table_query = "
  1665. CREATE TABLE vtiger_campaigngrouprelation (
  1666. `campaignid` int(19) NOT NULL,
  1667. `groupname` varchar(100) default NULL,
  1668. PRIMARY KEY (`campaignid`),
  1669. KEY `campaigngrouprelation_IDX1` (`groupname`),
  1670. CONSTRAINT `fk_campaigngrouprelation2` FOREIGN KEY (`groupname`) REFERENCES `vtiger_groups` (`groupname`) ON DELETE CASCADE,
  1671. CONSTRAINT `fk_campaigngrouprelation1` FOREIGN KEY (`campaignid`) REFERENCES `vtiger_campaign` (`campaignid`) ON DELETE CASCADE
  1672. ) ENGINE=InnoDB";
  1673. */
  1674. Execute($create_table_query);
  1675. //Added on 06-06-06
  1676. $create_query26 = "CREATE TABLE vtiger_campaignleadrel (
  1677. `campaignid` int(19) NOT NULL default '0',
  1678. `leadid` int(19) NOT NULL default '0',
  1679. PRIMARY KEY (`campaignid`),
  1680. KEY `campaignleadrel_leadid_campaignid_idx` (`leadid`,`campaignid`)
  1681. ) ENGINE=InnoDB";
  1682. /*
  1683. $create_query26 = "CREATE TABLE vtiger_campaignleadrel (
  1684. `campaignid` int(19) NOT NULL default '0',
  1685. `leadid` int(19) NOT NULL default '0',
  1686. PRIMARY KEY (`campaignid`),
  1687. KEY `CampaignLeadRel_IDX1` (`leadid`,`campaignid`),
  1688. CONSTRAINT `fk_CampaignLeadRel1234` FOREIGN KEY (`campaignid`) REFERENCES `vtiger_campaign` (`campaignid`) ON DELETE CASCADE,
  1689. CONSTRAINT `fk_CampaignLeadRel2423` FOREIGN KEY (`leadid`) REFERENCES `vtiger_leaddetails` (`leadid`) ON DELETE CASCADE
  1690. ) ENGINE=InnoDB";
  1691. */
  1692. Execute($create_query26);
  1693. $create_table_query1 = "CREATE TABLE vtiger_campaignscf (
  1694. `campaignid` int(19) NOT NULL default '0',
  1695. PRIMARY KEY (`campaignid`),
  1696. CONSTRAINT `fk_CampaignsCF` FOREIGN KEY (`campaignid`) REFERENCES `vtiger_campaign` (`campaignid`) ON DELETE CASCADE
  1697. ) ENGINE=InnoDB";
  1698. Execute($create_table_query1);
  1699. $alter_query_array18 = Array(
  1700. "alter table vtiger_potential add column campaignid int(19) default NULL after probability",
  1701. "alter table vtiger_potential drop column campaignsource",
  1702. //"alter table vtiger_notes drop PRIMARY KEY contact_id",
  1703. "alter table vtiger_notes drop PRIMARY KEY , add primary key(notesid)",
  1704. "update vtiger_field set uitype=99 where fieldname='update_log' and tabid=13"
  1705. );
  1706. foreach($alter_query_array18 as $query)
  1707. {
  1708. Execute($query);
  1709. }
  1710. //Added on 09-08-2006
  1711. //In the next array we have add constraint for tables purchaseorder, salesorder, quotes and invoice where as the corresponding entity ids should not be 0 they should be NULL. so that this change has been done
  1712. Execute("update vtiger_purchaseorder set contactid=NULL where contactid=0");
  1713. Execute("update vtiger_salesorder set contactid=NULL where contactid=0");
  1714. Execute("update vtiger_quotes set contactid=NULL where contactid=0");
  1715. Execute("update vtiger_quotes set potentialid=NULL where potentialid=0");
  1716. Execute("update vtiger_invoice set salesorderid=NULL where salesorderid=0");
  1717. //echo "<br><br><b>Database Modifications for Indexing and some missded tables starts here.....</b><br>";
  1718. //Added queries which are for indexing and the missing tables - Mickie - on 06-04-2006
  1719. $create_table_query_array = Array(
  1720. "CREATE TABLE vtiger_actualcost (
  1721. `actualcostid` int(19) NOT NULL auto_increment,
  1722. `actualcost` varchar(200) NOT NULL,
  1723. `sortorderid` int(19) NOT NULL default '0',
  1724. `presence` int(1) NOT NULL default '1',
  1725. PRIMARY KEY (`actualcostid`),
  1726. UNIQUE KEY `CampaignActCst_UK01` (`actualcost`)
  1727. ) ENGINE=InnoDB",
  1728. "CREATE TABLE vtiger_campaignstatus (
  1729. `campaignstatusid` int(19) NOT NULL auto_increment,
  1730. `campaignstatus` varchar(200) NOT NULL,
  1731. `sortorderid` int(19) NOT NULL default '0',
  1732. `presence` int(1) NOT NULL default '1',
  1733. PRIMARY KEY (`campaignstatusid`),
  1734. KEY `Campaignstatus_UK01` (`campaignstatus`)
  1735. ) ENGINE=InnoDB",
  1736. "CREATE TABLE vtiger_campaigntype (
  1737. `campaigntypeid` int(19) NOT NULL auto_increment,
  1738. `campaigntype` varchar(200) NOT NULL,
  1739. `sortorderid` int(19) NOT NULL default '0',
  1740. `presence` int(1) NOT NULL default '1',
  1741. PRIMARY KEY (`campaigntypeid`),
  1742. UNIQUE KEY `Campaigntype_UK01` (`campaigntype`)
  1743. ) ENGINE=InnoDB",
  1744. "CREATE TABLE vtiger_datashare_module_rel (
  1745. `shareid` int(19) NOT NULL,
  1746. `tabid` int(19) NOT NULL,
  1747. `relationtype` varchar(200) default NULL,
  1748. PRIMARY KEY (`shareid`),
  1749. KEY `idx_datashare_module_rel_tabid` (`tabid`)
  1750. ) ENGINE=InnoDB",
  1751. "CREATE TABLE vtiger_datashare_grp2grp (
  1752. `shareid` int(19) NOT NULL,
  1753. `share_groupid` int(19) default NULL,
  1754. `to_groupid` int(19) default NULL,
  1755. `permission` int(19) default NULL,
  1756. PRIMARY KEY (`shareid`),
  1757. KEY `datashare_grp2grp_share_groupid_idx` (`share_groupid`),
  1758. KEY `datashare_grp2grp_to_groupid_idx` (`to_groupid`)
  1759. ) ENGINE=InnoDB",
  1760. "CREATE TABLE vtiger_datashare_grp2role (
  1761. `shareid` int(19) NOT NULL,
  1762. `share_groupid` int(19) default NULL,
  1763. `to_roleid` varchar(255) default NULL,
  1764. `permission` int(19) default NULL,
  1765. PRIMARY KEY (`shareid`),
  1766. KEY `idx_datashare_grp2role_share_groupid` (`share_groupid`),
  1767. KEY `idx_datashare_grp2role_to_roleid` (`to_roleid`)
  1768. ) ENGINE=InnoDB",
  1769. "CREATE TABLE vtiger_datashare_grp2rs (
  1770. `shareid` int(19) NOT NULL,
  1771. `share_groupid` int(19) default NULL,
  1772. `to_roleandsubid` varchar(255) default NULL,
  1773. `permission` int(19) default NULL,
  1774. PRIMARY KEY (`shareid`),
  1775. KEY `datashare_grp2rs_share_groupid_idx` (`share_groupid`),
  1776. KEY `datashare_grp2rs_to_roleandsubid_idx` (`to_roleandsubid`)
  1777. ) ENGINE=InnoDB",
  1778. "CREATE TABLE vtiger_datashare_relatedmodule_permission (
  1779. `shareid` int(19) NOT NULL,
  1780. `datashare_relatedmodule_id` int(19) NOT NULL,
  1781. `permission` int(19) default NULL,
  1782. PRIMARY KEY (`shareid`,`datashare_relatedmodule_id`),
  1783. KEY `datashare_relatedmodule_permission_UK1` (`shareid`,`permission`)
  1784. ) ENGINE=InnoDB",
  1785. "CREATE TABLE vtiger_datashare_relatedmodules (
  1786. `datashare_relatedmodule_id` int(19) NOT NULL,
  1787. `tabid` int(19) default NULL,
  1788. `relatedto_tabid` int(19) default NULL,
  1789. PRIMARY KEY (`datashare_relatedmodule_id`),
  1790. KEY `datashare_relatedmodules_tabid_idx` (`tabid`),
  1791. KEY `datashare_relatedmodules_relatedto_tabid_idx` (`relatedto_tabid`)
  1792. ) ENGINE=InnoDB",
  1793. "CREATE TABLE vtiger_datashare_relatedmodules_seq (
  1794. `id` int(11) NOT NULL
  1795. ) ENGINE=InnoDB",
  1796. "CREATE TABLE vtiger_datashare_role2group (
  1797. `shareid` int(19) NOT NULL,
  1798. `share_roleid` varchar(255) default NULL,
  1799. `to_groupid` int(19) default NULL,
  1800. `permission` int(19) default NULL,
  1801. PRIMARY KEY (`shareid`),
  1802. KEY `idx_datashare_role2group_share_roleid` (`share_roleid`),
  1803. KEY `idx_datashare_role2group_to_groupid` (`to_groupid`)
  1804. ) ENGINE=InnoDB",
  1805. "CREATE TABLE vtiger_datashare_role2role (
  1806. `shareid` int(19) NOT NULL,
  1807. `share_roleid` varchar(255) default NULL,
  1808. `to_roleid` varchar(255) default NULL,
  1809. `permission` int(19) default NULL,
  1810. PRIMARY KEY (`shareid`),
  1811. KEY `datashare_role2role_share_roleid_idx` (`share_roleid`),
  1812. KEY `datashare_role2role_to_roleid_idx` (`to_roleid`)
  1813. ) ENGINE=InnoDB",
  1814. "CREATE TABLE vtiger_datashare_role2rs (
  1815. `shareid` int(19) NOT NULL,
  1816. `share_roleid` varchar(255) default NULL,
  1817. `to_roleandsubid` varchar(255) default NULL,
  1818. `permission` int(19) default NULL,
  1819. PRIMARY KEY (`shareid`),
  1820. KEY `datashare_role2s_share_roleid_idx` (`share_roleid`),
  1821. KEY `datashare_role2s_to_roleandsubid_idx` (`to_roleandsubid`)
  1822. ) ENGINE=InnoDB",
  1823. "CREATE TABLE vtiger_datashare_rs2grp (
  1824. `shareid` int(19) NOT NULL,
  1825. `share_roleandsubid` varchar(255) default NULL,
  1826. `to_groupid` int(19) default NULL,
  1827. `permission` int(19) default NULL,
  1828. PRIMARY KEY (`shareid`),
  1829. KEY `datashare_rs2grp_share_roleandsubid_idx` (`share_roleandsubid`),
  1830. KEY `datashare_rs2grp_to_groupid_idx` (`to_groupid`)
  1831. ) ENGINE=InnoDB",
  1832. "CREATE TABLE vtiger_datashare_rs2role (
  1833. `shareid` int(19) NOT NULL,
  1834. `share_roleandsubid` varchar(255) default NULL,
  1835. `to_roleid` varchar(255) default NULL,
  1836. `permission` int(19) default NULL,
  1837. PRIMARY KEY (`shareid`),
  1838. KEY `datashare_rs2role_share_roleandsubid_idx` (`share_roleandsubid`),
  1839. KEY `datashare_rs2role_to_roleid_idx` (`to_roleid`)
  1840. ) ENGINE=InnoDB",
  1841. "CREATE TABLE vtiger_datashare_rs2rs (
  1842. `shareid` int(19) NOT NULL,
  1843. `share_roleandsubid` varchar(255) default NULL,
  1844. `to_roleandsubid` varchar(255) default NULL,
  1845. `permission` int(19) default NULL,
  1846. PRIMARY KEY (`shareid`),
  1847. KEY `datashare_rs2rs_share_roleandsubid_idx` (`share_roleandsubid`),
  1848. KEY `idx_datashare_rs2rs_to_roleandsubid_idx` (`to_roleandsubid`)
  1849. ) ENGINE=InnoDB",
  1850. "CREATE TABLE vtiger_expectedresponse (
  1851. `expectedresponseid` int(19) NOT NULL auto_increment,
  1852. `expectedresponse` varchar(200) NOT NULL,
  1853. `sortorderid` int(19) NOT NULL default '0',
  1854. `presence` int(1) NOT NULL default '1',
  1855. PRIMARY KEY (`expectedresponseid`),
  1856. UNIQUE KEY `CampaignExpRes_UK01` (`expectedresponse`)
  1857. ) ENGINE=InnoDB",
  1858. "CREATE TABLE vtiger_expectedrevenue (
  1859. `expectedrevenueid` int(19) NOT NULL auto_increment,
  1860. `expectedrevenue` varchar(200) NOT NULL,
  1861. `sortorderid` int(19) NOT NULL default '0',
  1862. `presence` int(1) NOT NULL default '1',
  1863. PRIMARY KEY (`expectedrevenueid`),
  1864. UNIQUE KEY `CampaignExpRev_UK01` (`expectedrevenue`)
  1865. ) ENGINE=InnoDB",
  1866. "CREATE TABLE vtiger_tmp_read_group_rel_sharing_per (
  1867. `userid` int(11) NOT NULL,
  1868. `tabid` int(11) NOT NULL,
  1869. `relatedtabid` int(11) NOT NULL,
  1870. `sharedgroupid` int(11) NOT NULL,
  1871. PRIMARY KEY (`userid`,`tabid`,`relatedtabid`,`sharedgroupid`),
  1872. KEY `tmp_read_group_rel_sharing_per_userid_sharedgroupid_tabid` (`userid`,`sharedgroupid`,`tabid`)
  1873. ) ENGINE=InnoDB",
  1874. "CREATE TABLE vtiger_tmp_read_group_sharing_per (
  1875. `userid` int(11) NOT NULL,
  1876. `tabid` int(11) NOT NULL,
  1877. `sharedgroupid` int(11) NOT NULL,
  1878. PRIMARY KEY (`userid`,`tabid`,`sharedgroupid`),
  1879. KEY `tmp_read_group_sharing_per_userid_sharedgroupid_idx` (`userid`,`sharedgroupid`)
  1880. ) ENGINE=InnoDB",
  1881. "CREATE TABLE vtiger_tmp_read_user_rel_sharing_per (
  1882. `userid` int(11) NOT NULL,
  1883. `tabid` int(11) NOT NULL,
  1884. `relatedtabid` int(11) NOT NULL,
  1885. `shareduserid` int(11) NOT NULL,
  1886. PRIMARY KEY (`userid`,`tabid`,`relatedtabid`,`shareduserid`),
  1887. KEY `tmp_read_user_rel_sharing_per_userid_shared_reltabid_idx` (`userid`,`shareduserid`,`relatedtabid`)
  1888. ) ENGINE=InnoDB",
  1889. "CREATE TABLE vtiger_tmp_read_user_sharing_per (
  1890. `userid` int(11) NOT NULL,
  1891. `tabid` int(11) NOT NULL,
  1892. `shareduserid` int(11) NOT NULL,
  1893. PRIMARY KEY (`userid`,`tabid`,`shareduserid`),
  1894. KEY `tmp_read_user_sharing_per_userid_shareduserid_idx` (`userid`,`shareduserid`)
  1895. ) ENGINE=InnoDB",
  1896. "CREATE TABLE vtiger_tmp_write_group_rel_sharing_per (
  1897. `userid` int(11) NOT NULL,
  1898. `tabid` int(11) NOT NULL,
  1899. `relatedtabid` int(11) NOT NULL,
  1900. `sharedgroupid` int(11) NOT NULL,
  1901. PRIMARY KEY (`userid`,`tabid`,`relatedtabid`,`sharedgroupid`),
  1902. KEY `tmp_write_group_rel_sharing_per_userid_sharedgroupid_tabid_idx` (`userid`,`sharedgroupid`,`tabid`)
  1903. ) ENGINE=InnoDB",
  1904. "CREATE TABLE vtiger_tmp_write_group_sharing_per (
  1905. `userid` int(11) NOT NULL,
  1906. `tabid` int(11) NOT NULL,
  1907. `sharedgroupid` int(11) NOT NULL,
  1908. PRIMARY KEY (`userid`,`tabid`,`sharedgroupid`),
  1909. KEY `tmp_write_group_sharing_per_UK1` (`userid`,`sharedgroupid`)
  1910. ) ENGINE=InnoDB",
  1911. "CREATE TABLE vtiger_tmp_write_user_rel_sharing_per (
  1912. `userid` int(11) NOT NULL,
  1913. `tabid` int(11) NOT NULL,
  1914. `relatedtabid` int(11) NOT NULL,
  1915. `shareduserid` int(11) NOT NULL,
  1916. PRIMARY KEY (`userid`,`tabid`,`relatedtabid`,`shareduserid`),
  1917. KEY `tmp_write_user_rel_sharing_per_userid_sharduserid_tabid_idx` (`userid`,`shareduserid`,`tabid`)
  1918. ) ENGINE=InnoDB",
  1919. "CREATE TABLE vtiger_tmp_write_user_sharing_per (
  1920. `userid` int(11) NOT NULL,
  1921. `tabid` int(11) NOT NULL,
  1922. `shareduserid` int(11) NOT NULL,
  1923. PRIMARY KEY (`userid`,`tabid`,`shareduserid`),
  1924. KEY `tmp_write_user_sharing_per_userid_shareduserid_idx` (`userid`,`shareduserid`)
  1925. ) ENGINE=InnoDB",
  1926. );
  1927. foreach($create_table_query_array as $query)
  1928. {
  1929. Execute($query);
  1930. }
  1931. $query_array = Array(
  1932. //"ALTER TABLE `vtiger_activity` DROP INDEX `status`",
  1933. //"ALTER TABLE `vtiger_contactgrouprelation` DROP INDEX `fk_contactgrouprelation2`",
  1934. //"ALTER TABLE `vtiger_customview` DROP INDEX `customview`",
  1935. //"ALTER TABLE `vtiger_def_org_field` DROP INDEX `tabid`",
  1936. //"ALTER TABLE `vtiger_field` DROP INDEX `tabid`",
  1937. //"ALTER TABLE `vtiger_groups` DROP INDEX `groupname`",
  1938. //"ALTER TABLE `vtiger_invoicegrouprelation` DROP INDEX `fk_invoicegrouprelation2`",
  1939. //"ALTER TABLE `vtiger_pogrouprelation` DROP INDEX `fk_productgrouprelation2`",
  1940. //"ALTER TABLE `vtiger_potential` DROP INDEX `potentialid`",
  1941. //"ALTER TABLE `vtiger_potentialgrouprelation` DROP INDEX `fk_potentialgrouprelation2`",
  1942. //"ALTER TABLE `vtiger_profile2field` DROP INDEX `tabid`",
  1943. "ALTER TABLE `vtiger_profile2tab` DROP INDEX `idx_profile2tab`",
  1944. "ALTER TABLE `vtiger_profile2tab` ADD KEY `profile2tab_profileid_tabid_idx` (`profileid`, `tabid`)",
  1945. //"ALTER TABLE `vtiger_quotegrouprelation` DROP INDEX `fk_quotegrouprelation2`",
  1946. "ALTER TABLE `vtiger_reportmodules` DROP INDEX `reportmodules_IDX0`",
  1947. "ALTER TABLE `vtiger_reportmodules` MODIFY COLUMN `reportmodulesid` INTEGER(19) NOT NULL",
  1948. "ALTER TABLE `vtiger_reportsortcol` DROP INDEX `reportsortcol_IDX0`",
  1949. "ALTER TABLE `vtiger_reportsortcol` ADD KEY `fk_1_vtiger_reportsortcol` (`reportid`)",
  1950. "ALTER TABLE `vtiger_reportsortcol` MODIFY COLUMN `sortcolid` INTEGER(19) NOT NULL",
  1951. "ALTER TABLE `vtiger_reportsortcol` MODIFY COLUMN `reportid` INTEGER(19) NOT NULL",
  1952. "ALTER TABLE `vtiger_reportsummary` DROP INDEX `reportsummary_IDX0`",
  1953. "ALTER TABLE `vtiger_reportsummary` ADD KEY `reportsummary_reportsummaryid_idx` (`reportsummaryid`)",
  1954. "ALTER TABLE `vtiger_reportsummary` MODIFY COLUMN `reportsummaryid` INTEGER(19) NOT NULL",
  1955. "ALTER TABLE `vtiger_reportsummary` MODIFY COLUMN `summarytype` INTEGER(19) NOT NULL",
  1956. //"ALTER TABLE `vtiger_seattachmentsrel` DROP INDEX `attachmentsid`",
  1957. //"ALTER TABLE `vtiger_sogrouprelation` DROP INDEX `fk_sogrouprelation2`",
  1958. //"ALTER TABLE `vtiger_tab` DROP INDEX `tabid`",
  1959. //"ALTER TABLE `vtiger_troubletickets` DROP INDEX `status`",
  1960. "ALTER TABLE `vtiger_activity_reminder` TYPE=InnoDB",
  1961. "ALTER TABLE `vtiger_activsubtype` TYPE=InnoDB",
  1962. "ALTER TABLE `vtiger_contactgrouprelation` TYPE=InnoDB",
  1963. //"ALTER TABLE `vtiger_customerdetails` TYPE=InnoDB",
  1964. "ALTER TABLE `vtiger_customview_seq` TYPE=InnoDB",
  1965. "ALTER TABLE `vtiger_def_org_field` TYPE=InnoDB",
  1966. "ALTER TABLE `vtiger_def_org_share` TYPE=InnoDB",
  1967. "ALTER TABLE `vtiger_def_org_share_seq` TYPE=InnoDB",
  1968. //"ALTER TABLE `vtiger_defaultcv` TYPE=InnoDB",
  1969. "ALTER TABLE `vtiger_durationhrs` TYPE=InnoDB",
  1970. "ALTER TABLE `vtiger_durationmins` TYPE=InnoDB",
  1971. "ALTER TABLE `vtiger_emailtemplates` TYPE=InnoDB",
  1972. //"ALTER TABLE `vtiger_emailtemplates_seq` TYPE=InnoDB",
  1973. "ALTER TABLE `vtiger_faqcategories` TYPE=InnoDB",
  1974. "ALTER TABLE `vtiger_faqstatus` TYPE=InnoDB",
  1975. "ALTER TABLE `vtiger_field_seq` TYPE=InnoDB",
  1976. "ALTER TABLE `vtiger_files` TYPE=InnoDB",
  1977. "ALTER TABLE `vtiger_group2grouprel` TYPE=InnoDB",
  1978. "ALTER TABLE `vtiger_group2role` TYPE=InnoDB",
  1979. "ALTER TABLE `vtiger_group2rs` TYPE=InnoDB",
  1980. //"DROP TABLE `groups_seq`",
  1981. "ALTER TABLE `vtiger_headers` TYPE=InnoDB",
  1982. "ALTER TABLE `vtiger_import_maps` TYPE=InnoDB",
  1983. "ALTER TABLE `vtiger_inventorynotification_seq` TYPE=InnoDB",
  1984. "ALTER TABLE `vtiger_invoicegrouprelation` TYPE=InnoDB",
  1985. "ALTER TABLE `vtiger_loginhistory` TYPE=InnoDB",
  1986. "ALTER TABLE `vtiger_mail_accounts` TYPE=InnoDB",
  1987. "ALTER TABLE `vtiger_notificationscheduler_seq` TYPE=InnoDB",
  1988. "ALTER TABLE `vtiger_ownernotify` TYPE=InnoDB",
  1989. "ALTER TABLE `vtiger_parenttabrel` TYPE=InnoDB",
  1990. "ALTER TABLE `vtiger_pogrouprelation` TYPE=InnoDB",
  1991. "ALTER TABLE `vtiger_portal` TYPE=InnoDB",
  1992. "ALTER TABLE `vtiger_portalinfo` TYPE=InnoDB",
  1993. "ALTER TABLE `vtiger_potentialgrouprelation` TYPE=InnoDB",
  1994. "ALTER TABLE `vtiger_profile2field` TYPE=InnoDB",
  1995. "ALTER TABLE `vtiger_reportmodules` TYPE=InnoDB",
  1996. "ALTER TABLE `vtiger_profile2globalpermissions` TYPE=InnoDB",
  1997. "ALTER TABLE `vtiger_profile2standardpermissions` TYPE=InnoDB",
  1998. "ALTER TABLE `vtiger_profile2tab` TYPE=InnoDB",
  1999. "ALTER TABLE `vtiger_profile2utility` TYPE=InnoDB",
  2000. "ALTER TABLE `vtiger_profile_seq` TYPE=InnoDB",
  2001. "ALTER TABLE `vtiger_quotegrouprelation` TYPE=InnoDB",
  2002. "ALTER TABLE `vtiger_rating` TYPE=InnoDB",
  2003. "ALTER TABLE `vtiger_relatedlists` TYPE=InnoDB",
  2004. "ALTER TABLE `vtiger_relatedlists_seq` TYPE=InnoDB",
  2005. "ALTER TABLE `vtiger_role2profile` TYPE=InnoDB",
  2006. "ALTER TABLE `vtiger_role_seq` TYPE=InnoDB",
  2007. "ALTER TABLE `vtiger_rss` TYPE=InnoDB",
  2008. "ALTER TABLE `vtiger_sales_stage` TYPE=InnoDB",
  2009. "ALTER TABLE `vtiger_salutationtype` TYPE=InnoDB",
  2010. "ALTER TABLE `vtiger_selectquery_seq` TYPE=InnoDB",
  2011. "ALTER TABLE `vtiger_sogrouprelation` TYPE=InnoDB",
  2012. "ALTER TABLE `vtiger_systems` TYPE=InnoDB",
  2013. "ALTER TABLE `vtiger_taskpriority` TYPE=InnoDB",
  2014. "ALTER TABLE `vtiger_taskstatus` TYPE=InnoDB",
  2015. "ALTER TABLE `vtiger_ticketcategories` TYPE=InnoDB",
  2016. "ALTER TABLE `vtiger_ticketpriorities` TYPE=InnoDB",
  2017. "ALTER TABLE `vtiger_ticketseverities` TYPE=InnoDB",
  2018. "ALTER TABLE `vtiger_ticketstatus` TYPE=InnoDB",
  2019. "ALTER TABLE `vtiger_ticketstracktime` TYPE=InnoDB",
  2020. "ALTER TABLE `vtiger_tracker` TYPE=InnoDB",
  2021. "ALTER TABLE `vtiger_users2group` TYPE=InnoDB",
  2022. "ALTER TABLE `vtiger_users_last_import` TYPE=InnoDB",
  2023. "ALTER TABLE `vtiger_users_seq` TYPE=InnoDB",
  2024. //"ALTER TABLE `vtiger_wordtemplates` TYPE=InnoDB",
  2025. //Create table queries are moved from here to above this array
  2026. "ALTER TABLE `vtiger_account` MODIFY COLUMN `website` VARCHAR(100) DEFAULT NULL",
  2027. //"ALTER TABLE `vtiger_activity` MODIFY COLUMN `date_start` DATE NOT NULL UNIQUE",
  2028. "ALTER TABLE `vtiger_activity` MODIFY COLUMN `sendnotification` VARCHAR(3) NOT NULL DEFAULT '0'",
  2029. "ALTER TABLE `vtiger_activity` MODIFY COLUMN `duration_hours` VARCHAR(2) DEFAULT NULL",
  2030. "ALTER TABLE `vtiger_activity` MODIFY COLUMN `duration_minutes` VARCHAR(2) DEFAULT NULL",
  2031. "ALTER TABLE `vtiger_activity_reminder` MODIFY COLUMN `reminder_time` INTEGER(11) NOT NULL",
  2032. "ALTER TABLE `vtiger_activity_reminder` MODIFY COLUMN `reminder_sent` INTEGER(2) NOT NULL",
  2033. //"ALTER TABLE `vtiger_blocks` MODIFY COLUMN `tabid` INTEGER(19) NOT NULL UNIQUE",
  2034. "ALTER TABLE `vtiger_blocks` MODIFY COLUMN `sequence` INTEGER(10) DEFAULT NULL",
  2035. "ALTER TABLE `vtiger_blocks` MODIFY COLUMN `show_title` INTEGER(2) DEFAULT NULL",
  2036. //HANDLE HERE - MICKIE - Check the following queries
  2037. "ALTER TABLE `vtiger_contactdetails` MODIFY COLUMN `donotcall` VARCHAR(3) DEFAULT NULL",
  2038. "ALTER TABLE `vtiger_contactdetails` MODIFY COLUMN `emailoptout` VARCHAR(3) DEFAULT '0'",
  2039. "ALTER TABLE `vtiger_contactdetails` MODIFY COLUMN `imagename` VARCHAR(150) DEFAULT NULL",
  2040. "ALTER TABLE `vtiger_contactdetails` MODIFY COLUMN `reference` VARCHAR(3) DEFAULT NULL",
  2041. //"ALTER TABLE `vtiger_contactgrouprelation` MODIFY COLUMN `contactid` INTEGER(19) NOT NULL PRIMARY KEY",
  2042. //"ALTER TABLE `vtiger_convertleadmapping` MODIFY COLUMN `leadfid` INTEGER(19) NOT NULL",
  2043. //"ALTER TABLE `vtiger_crmentity` MODIFY COLUMN `crmid` INTEGER(19) NOT NULL PRIMARY KEY",
  2044. "ALTER TABLE `vtiger_crmentity` MODIFY COLUMN `description` TEXT",
  2045. "ALTER TABLE `vtiger_crmentity` MODIFY COLUMN `createdtime` DATETIME NOT NULL",
  2046. "ALTER TABLE `vtiger_crmentity` MODIFY COLUMN `modifiedtime` DATETIME NOT NULL",
  2047. "ALTER TABLE `vtiger_customaction` MODIFY COLUMN `cvid` INTEGER(19) NOT NULL UNIQUE",
  2048. "ALTER TABLE `vtiger_customaction` MODIFY COLUMN `content` TEXT",
  2049. //"ALTER TABLE `vtiger_customerdetails` MODIFY COLUMN `customerid` INTEGER(19) NOT NULL PRIMARY KEY",
  2050. "ALTER TABLE `vtiger_customerdetails` MODIFY COLUMN `portal` VARCHAR(3) DEFAULT NULL",
  2051. //"ALTER TABLE `vtiger_customview` MODIFY COLUMN `cvid` INTEGER(19) NOT NULL PRIMARY KEY",
  2052. "ALTER TABLE `vtiger_customview_seq` MODIFY COLUMN `id` INTEGER(11) NOT NULL",
  2053. //"ALTER TABLE `vtiger_cvadvfilter` MODIFY COLUMN `cvid` INTEGER(19) NOT NULL PRIMARY KEY",
  2054. //"ALTER TABLE `vtiger_cvadvfilter` MODIFY COLUMN `columnindex` INTEGER(11) NOT NULL PRIMARY KEY",
  2055. //"ALTER TABLE `vtiger_cvcolumnlist` MODIFY COLUMN `cvid` INTEGER(19) NOT NULL PRIMARY KEY",
  2056. //"ALTER TABLE `vtiger_cvcolumnlist` MODIFY COLUMN `columnindex` INTEGER(11) NOT NULL PRIMARY KEY",
  2057. //"ALTER TABLE `vtiger_cvstdfilter` MODIFY COLUMN `cvid` INTEGER(19) NOT NULL PRIMARY KEY",
  2058. "ALTER TABLE `vtiger_dealintimation` MODIFY COLUMN `dealprobability` DECIMAL(3,2) NOT NULL DEFAULT '0.00'",
  2059. //"ALTER TABLE `vtiger_def_org_field` MODIFY COLUMN `fieldid` INTEGER(19) NOT NULL PRIMARY KEY",
  2060. "ALTER TABLE `vtiger_def_org_share` MODIFY COLUMN `tabid` INTEGER(11) NOT NULL",
  2061. //"ALTER TABLE `vtiger_def_org_share` MODIFY COLUMN `permission` INTEGER(19) DEFAULT NULL UNIQUE",
  2062. "ALTER TABLE `vtiger_def_org_share_seq` MODIFY COLUMN `id` INTEGER(11) NOT NULL",
  2063. //"ALTER TABLE `vtiger_defaultcv` MODIFY COLUMN `tabid` INTEGER(19) NOT NULL PRIMARY KEY",
  2064. "ALTER TABLE `vtiger_defaultcv` MODIFY COLUMN `query` TEXT",
  2065. "ALTER TABLE `vtiger_emailtemplates` MODIFY COLUMN `description` TEXT",
  2066. "ALTER TABLE `vtiger_emailtemplates` MODIFY COLUMN `body` TEXT",
  2067. //"ALTER TABLE `vtiger_emailtemplates_seq` MODIFY COLUMN `id` INTEGER(11) NOT NULL",
  2068. "ALTER TABLE `vtiger_faq` MODIFY COLUMN `question` TEXT",
  2069. "ALTER TABLE `vtiger_faq` MODIFY COLUMN `answer` TEXT",
  2070. "ALTER TABLE `vtiger_faqcomments` MODIFY COLUMN `comments` TEXT",
  2071. "ALTER TABLE `vtiger_faqcomments` MODIFY COLUMN `createdtime` DATETIME NOT NULL",
  2072. //"ALTER TABLE `vtiger_field` MODIFY COLUMN `tabid` INTEGER(19) NOT NULL UNIQUE",
  2073. "ALTER TABLE `vtiger_field` MODIFY COLUMN `readonly` INTEGER(1) NOT NULL",
  2074. "ALTER TABLE `vtiger_field` MODIFY COLUMN `selected` INTEGER(1) NOT NULL",
  2075. //"ALTER TABLE `vtiger_field` MODIFY COLUMN `block` INTEGER(19) DEFAULT NULL UNIQUE",
  2076. //"ALTER TABLE `vtiger_field` MODIFY COLUMN `displaytype` INTEGER(19) DEFAULT NULL UNIQUE",
  2077. "ALTER TABLE `vtiger_field` MODIFY COLUMN `quickcreate` INTEGER(10) NOT NULL DEFAULT '1'",
  2078. "ALTER TABLE `vtiger_field_seq` MODIFY COLUMN `id` INTEGER(11) NOT NULL",
  2079. //"ALTER TABLE `vtiger_group2grouprel` MODIFY COLUMN `groupid` INTEGER(19) NOT NULL PRIMARY KEY",
  2080. //"ALTER TABLE `vtiger_group2grouprel` MODIFY COLUMN `containsgroupid` INTEGER(19) NOT NULL PRIMARY KEY",
  2081. //"ALTER TABLE `vtiger_group2role` MODIFY COLUMN `groupid` INTEGER(19) NOT NULL PRIMARY KEY",
  2082. //"ALTER TABLE `vtiger_group2rs` MODIFY COLUMN `groupid` INTEGER(19) NOT NULL PRIMARY KEY",
  2083. //"ALTER TABLE `vtiger_groups` MODIFY COLUMN `groupid` INTEGER(19) NOT NULL PRIMARY KEY",
  2084. "ALTER TABLE `vtiger_groups` MODIFY COLUMN `description` TEXT",
  2085. "ALTER TABLE `vtiger_import_maps` MODIFY COLUMN `is_published` VARCHAR(3) NOT NULL DEFAULT 'no'",
  2086. //"ALTER TABLE `vtiger_inventory_tandc` MODIFY COLUMN `id` INTEGER(19) NOT NULL PRIMARY KEY",
  2087. "ALTER TABLE `vtiger_inventory_tandc` MODIFY COLUMN `tandc` TEXT",
  2088. "ALTER TABLE `vtiger_inventory_tandc_seq` MODIFY COLUMN `id` INTEGER(11) NOT NULL",
  2089. "ALTER TABLE `vtiger_inventorynotification` MODIFY COLUMN `notificationbody` TEXT",
  2090. "ALTER TABLE `vtiger_inventorynotification_seq` MODIFY COLUMN `id` INTEGER(11) NOT NULL",
  2091. //"ALTER TABLE `vtiger_invoice` MODIFY COLUMN `salesorderid` INTEGER(19) DEFAULT NULL UNIQUE",
  2092. "ALTER TABLE `vtiger_invoice` MODIFY COLUMN `terms_conditions` TEXT",
  2093. //"ALTER TABLE `vtiger_invoicegrouprelation` MODIFY COLUMN `invoiceid` INTEGER(19) NOT NULL PRIMARY KEY",
  2094. "ALTER TABLE `vtiger_lar` MODIFY COLUMN `createdon` DATE NOT NULL",
  2095. //"ALTER TABLE `vtiger_leaddetails` MODIFY COLUMN `leadid` INTEGER(19) NOT NULL PRIMARY KEY",
  2096. "ALTER TABLE `vtiger_leaddetails` MODIFY COLUMN `comments` TEXT",
  2097. //"ALTER TABLE `vtiger_leadgrouprelation` MODIFY COLUMN `leadid` INTEGER(19) NOT NULL PRIMARY KEY",
  2098. //"ALTER TABLE `vtiger_mail_accounts` MODIFY COLUMN `account_id` INTEGER(11) NOT NULL PRIMARY KEY",
  2099. "ALTER TABLE `vtiger_mail_accounts` MODIFY COLUMN `user_id` INTEGER(11) NOT NULL",
  2100. "ALTER TABLE `vtiger_mail_accounts` ADD COLUMN `box_refresh` INTEGER(10) DEFAULT NULL",
  2101. "ALTER TABLE `vtiger_mail_accounts` ADD COLUMN `mails_per_page` INTEGER(10) DEFAULT NULL",
  2102. "ALTER TABLE `vtiger_mail_accounts` ADD COLUMN `ssltype` VARCHAR(50) DEFAULT NULL",
  2103. "ALTER TABLE `vtiger_mail_accounts` ADD COLUMN `sslmeth` VARCHAR(50) DEFAULT NULL",
  2104. "ALTER TABLE `vtiger_mail_accounts` ADD COLUMN `showbody` VARCHAR(10) DEFAULT NULL",
  2105. "ALTER TABLE `vtiger_notes` MODIFY COLUMN `contact_id` INTEGER(19) DEFAULT '0'",
  2106. "ALTER TABLE `vtiger_notes` MODIFY COLUMN `notecontent` TEXT",
  2107. "ALTER TABLE `vtiger_notificationscheduler` MODIFY COLUMN `notificationbody` TEXT",
  2108. "ALTER TABLE `vtiger_notificationscheduler_seq` MODIFY COLUMN `id` INTEGER(11) NOT NULL",
  2109. "ALTER TABLE `vtiger_opportunitystage` MODIFY COLUMN `probability` DECIMAL(3,2) DEFAULT '0.00'",
  2110. //"ALTER TABLE `vtiger_org_share_action2tab` MODIFY COLUMN `share_action_id` INTEGER(19) NOT NULL PRIMARY KEY",
  2111. //"ALTER TABLE `vtiger_org_share_action2tab` MODIFY COLUMN `tabid` INTEGER(19) NOT NULL PRIMARY KEY",
  2112. //"ALTER TABLE `vtiger_org_share_action_mapping` MODIFY COLUMN `share_action_id` INTEGER(19) NOT NULL PRIMARY KEY",
  2113. "ALTER TABLE `vtiger_organizationdetails` MODIFY COLUMN `website` VARCHAR(100) DEFAULT NULL",
  2114. "ALTER TABLE `vtiger_organizationdetails` MODIFY COLUMN `logo` TEXT",
  2115. "ALTER TABLE `vtiger_ownernotify` MODIFY COLUMN `crmid` INTEGER(19) DEFAULT NULL UNIQUE",
  2116. //"ALTER TABLE `vtiger_parenttab` MODIFY COLUMN `parenttabid` INTEGER(19) NOT NULL PRIMARY KEY",
  2117. "ALTER TABLE `vtiger_parenttab` MODIFY COLUMN `sequence` INTEGER(10) NOT NULL",
  2118. "ALTER TABLE `vtiger_parenttabrel` MODIFY COLUMN `parenttabid` INTEGER(3) NOT NULL",
  2119. //"ALTER TABLE `vtiger_parenttabrel` MODIFY COLUMN `tabid` INTEGER(3) NOT NULL UNIQUE",
  2120. "ALTER TABLE `vtiger_parenttabrel` MODIFY COLUMN `sequence` INTEGER(3) NOT NULL",
  2121. //"ALTER TABLE `vtiger_pogrouprelation` MODIFY COLUMN `purchaseorderid` INTEGER(19) NOT NULL PRIMARY KEY",
  2122. //"ALTER TABLE `vtiger_portal` MODIFY COLUMN `portalid` INTEGER(19) NOT NULL PRIMARY KEY",
  2123. "ALTER TABLE `vtiger_portal` MODIFY COLUMN `portalname` VARCHAR(200) NOT NULL UNIQUE",
  2124. "ALTER TABLE `vtiger_portal` MODIFY COLUMN `sequence` INTEGER(3) NOT NULL",
  2125. //"ALTER TABLE `vtiger_portalinfo` MODIFY COLUMN `id` INTEGER(11) NOT NULL PRIMARY KEY",
  2126. "ALTER TABLE `vtiger_portalinfo` MODIFY COLUMN `last_login_time` DATETIME NOT NULL",
  2127. "ALTER TABLE `vtiger_portalinfo` MODIFY COLUMN `login_time` DATETIME NOT NULL",
  2128. "ALTER TABLE `vtiger_portalinfo` MODIFY COLUMN `logout_time` DATETIME NOT NULL",
  2129. //"ALTER TABLE `vtiger_potcompetitorrel` MODIFY COLUMN `potentialid` INTEGER(19) NOT NULL PRIMARY KEY",
  2130. //"ALTER TABLE `vtiger_potcompetitorrel` MODIFY COLUMN `competitorid` INTEGER(19) NOT NULL PRIMARY KEY",
  2131. "ALTER TABLE `vtiger_potential` MODIFY COLUMN `amount` DECIMAL(10,2) DEFAULT '0.00'",
  2132. "ALTER TABLE `vtiger_potential` MODIFY COLUMN `description` TEXT",
  2133. //"ALTER TABLE `vtiger_potentialgrouprelation` MODIFY COLUMN `potentialid` INTEGER(19) NOT NULL PRIMARY KEY",
  2134. "ALTER TABLE `vtiger_potstagehistory` MODIFY COLUMN `potentialid` INTEGER(19) NOT NULL",
  2135. "ALTER TABLE `vtiger_potstagehistory` MODIFY COLUMN `probability` DECIMAL(7,3) DEFAULT NULL",
  2136. "ALTER TABLE `vtiger_potstagehistory` MODIFY COLUMN `lastmodified` DATETIME default NULL",
  2137. "ALTER TABLE `vtiger_pricebook` MODIFY COLUMN `description` TEXT",
  2138. //"ALTER TABLE `vtiger_pricebookproductrel` MODIFY COLUMN `pricebookid` INTEGER(19) NOT NULL PRIMARY KEY",
  2139. //"ALTER TABLE `vtiger_pricebookproductrel` MODIFY COLUMN `productid` INTEGER(19) NOT NULL PRIMARY KEY",
  2140. //"ALTER TABLE `vtiger_productcollaterals` MODIFY COLUMN `productid` INTEGER(11) NOT NULL PRIMARY KEY",
  2141. "ALTER TABLE `vtiger_productcollaterals` MODIFY COLUMN `description` TEXT",
  2142. //"ALTER TABLE `vtiger_products` MODIFY COLUMN `productid` INTEGER(11) NOT NULL PRIMARY KEY",
  2143. "ALTER TABLE `vtiger_products` MODIFY COLUMN `product_description` TEXT",
  2144. "ALTER TABLE `vtiger_products` MODIFY COLUMN `commissionrate` DECIMAL(3,3) DEFAULT NULL",
  2145. //"ALTER TABLE `vtiger_profile2field` MODIFY COLUMN `profileid` INTEGER(11) NOT NULL PRIMARY KEY",
  2146. //"ALTER TABLE `vtiger_profile2field` MODIFY COLUMN `fieldid` INTEGER(19) NOT NULL PRIMARY KEY",
  2147. //"ALTER TABLE `vtiger_profile2globalpermissions` MODIFY COLUMN `profileid` INTEGER(19) NOT NULL PRIMARY KEY",
  2148. //"ALTER TABLE `vtiger_profile2globalpermissions` MODIFY COLUMN `globalactionid` INTEGER(19) NOT NULL PRIMARY KEY",
  2149. //"ALTER TABLE `vtiger_profile2standardpermissions` MODIFY COLUMN `profileid` INTEGER(11) NOT NULL PRIMARY KEY",
  2150. //"ALTER TABLE `vtiger_profile2standardpermissions` MODIFY COLUMN `tabid` INTEGER(10) NOT NULL PRIMARY KEY",
  2151. //"ALTER TABLE `vtiger_profile2standardpermissions` MODIFY COLUMN `Operation` INTEGER(10) NOT NULL PRIMARY KEY",
  2152. //"ALTER TABLE `vtiger_profile2utility` MODIFY COLUMN `profileid` INTEGER(11) NOT NULL PRIMARY KEY",
  2153. //"ALTER TABLE `vtiger_profile2utility` MODIFY COLUMN `tabid` INTEGER(11) NOT NULL PRIMARY KEY",
  2154. //"ALTER TABLE `vtiger_profile2utility` MODIFY COLUMN `activityid` INTEGER(11) NOT NULL PRIMARY KEY",
  2155. "ALTER TABLE `vtiger_profile_seq` MODIFY COLUMN `id` INTEGER(11) NOT NULL",
  2156. //"ALTER TABLE `vtiger_purchaseorder` MODIFY COLUMN `quoteid` INTEGER(19) DEFAULT NULL UNIQUE",
  2157. //"ALTER TABLE `vtiger_purchaseorder` MODIFY COLUMN `vendorid` INTEGER(19) DEFAULT NULL UNIQUE",
  2158. //"ALTER TABLE `vtiger_purchaseorder` MODIFY COLUMN `contactid` INTEGER(19) DEFAULT NULL UNIQUE",
  2159. "ALTER TABLE `vtiger_purchaseorder` MODIFY COLUMN `terms_conditions` TEXT",
  2160. //"ALTER TABLE `vtiger_quotegrouprelation` MODIFY COLUMN `quoteid` INTEGER(19) NOT NULL PRIMARY KEY",
  2161. //"ALTER TABLE `vtiger_quotes` MODIFY COLUMN `potentialid` INTEGER(19) DEFAULT NULL UNIQUE",
  2162. "ALTER TABLE `vtiger_quotes` MODIFY COLUMN `quotestage` VARCHAR(200) DEFAULT NULL",
  2163. //"ALTER TABLE `vtiger_quotes` MODIFY COLUMN `contactid` INTEGER(19) DEFAULT NULL UNIQUE",
  2164. "ALTER TABLE `vtiger_quotes` MODIFY COLUMN `terms_conditions` TEXT",
  2165. "ALTER TABLE `vtiger_recurringevents` MODIFY COLUMN `activityid` INTEGER(19) NOT NULL",
  2166. //"ALTER TABLE `vtiger_relatedlists` MODIFY COLUMN `relation_id` INTEGER(19) NOT NULL PRIMARY KEY",
  2167. "ALTER TABLE `vtiger_relatedlists_seq` MODIFY COLUMN `id` INTEGER(11) NOT NULL",
  2168. //"ALTER TABLE `vtiger_relcriteria` MODIFY COLUMN `queryid` INTEGER(19) NOT NULL PRIMARY KEY",
  2169. //"ALTER TABLE `vtiger_relcriteria` MODIFY COLUMN `columnindex` INTEGER(11) NOT NULL PRIMARY KEY",
  2170. //"ALTER TABLE `vtiger_report` MODIFY COLUMN `reportid` INTEGER(19) NOT NULL PRIMARY KEY",
  2171. //"ALTER TABLE `vtiger_report` MODIFY COLUMN `folderid` INTEGER(19) NOT NULL UNIQUE",
  2172. //"ALTER TABLE `vtiger_reportdatefilter` MODIFY COLUMN `datefilterid` INTEGER(19) NOT NULL PRIMARY KEY",
  2173. //"ALTER TABLE `vtiger_role2profile` MODIFY COLUMN `profileid` INTEGER(11) NOT NULL PRIMARY KEY",
  2174. "ALTER TABLE `vtiger_role_seq` MODIFY COLUMN `id` INTEGER(11) NOT NULL",
  2175. //"ALTER TABLE `vtiger_rss` MODIFY COLUMN `rssid` INTEGER(19) NOT NULL PRIMARY KEY",
  2176. //"ALTER TABLE `vtiger_salesorder` MODIFY COLUMN `contactid` INTEGER(19) DEFAULT NULL UNIQUE",
  2177. "ALTER TABLE `vtiger_salesorder` MODIFY COLUMN `vendorid` INTEGER(19) DEFAULT NULL UNIQUE",
  2178. "ALTER TABLE `vtiger_salesorder` MODIFY COLUMN `terms_conditions` TEXT",
  2179. //"ALTER TABLE `vtiger_seactivityrel` MODIFY COLUMN `crmid` INTEGER(19) NOT NULL PRIMARY KEY",
  2180. //"ALTER TABLE `vtiger_seactivityrel` MODIFY COLUMN `activityid` INTEGER(19) NOT NULL PRIMARY KEY",
  2181. //"ALTER TABLE `vtiger_selectcolumn` MODIFY COLUMN `queryid` INTEGER(19) NOT NULL PRIMARY KEY",
  2182. //"ALTER TABLE `vtiger_selectquery` MODIFY COLUMN `queryid` INTEGER(19) NOT NULL PRIMARY KEY",
  2183. "ALTER TABLE `vtiger_selectquery_seq` MODIFY COLUMN `id` INTEGER(11) NOT NULL",
  2184. //"ALTER TABLE `vtiger_sharedcalendar` MODIFY COLUMN `userid` INTEGER(19) NOT NULL PRIMARY KEY",
  2185. //"ALTER TABLE `vtiger_sharedcalendar` MODIFY COLUMN `sharedid` INTEGER(19) NOT NULL PRIMARY KEY",
  2186. //"ALTER TABLE `vtiger_sogrouprelation` MODIFY COLUMN `salesorderid` INTEGER(19) NOT NULL PRIMARY KEY",
  2187. //"ALTER TABLE `vtiger_systems` MODIFY COLUMN `id` INTEGER(19) NOT NULL PRIMARY KEY",
  2188. "ALTER TABLE `vtiger_systems` MODIFY COLUMN `server` VARCHAR(30) DEFAULT NULL",
  2189. "ALTER TABLE `vtiger_systems` MODIFY COLUMN `server_username` VARCHAR(30) DEFAULT NULL",
  2190. "ALTER TABLE `vtiger_systems` MODIFY COLUMN `server_password` VARCHAR(30) DEFAULT NULL",
  2191. "ALTER TABLE `vtiger_ticketcomments` MODIFY COLUMN `comments` TEXT",
  2192. "ALTER TABLE `vtiger_ticketcomments` MODIFY COLUMN `createdtime` DATETIME NOT NULL",
  2193. //"ALTER TABLE `vtiger_ticketgrouprelation` MODIFY COLUMN `ticketid` INTEGER(19) NOT NULL PRIMARY KEY",
  2194. //"ALTER TABLE `vtiger_troubletickets` MODIFY COLUMN `ticketid` INTEGER(19) NOT NULL PRIMARY KEY",
  2195. "ALTER TABLE `vtiger_troubletickets` MODIFY COLUMN `description` TEXT",
  2196. "ALTER TABLE `vtiger_troubletickets` MODIFY COLUMN `solution` TEXT",
  2197. "ALTER TABLE `vtiger_troubletickets` MODIFY COLUMN `update_log` TEXT",
  2198. //"ALTER TABLE `vtiger_user2role` MODIFY COLUMN `userid` INTEGER(11) NOT NULL PRIMARY KEY",
  2199. //"ALTER TABLE `vtiger_user2role` MODIFY COLUMN `roleid` VARCHAR(255) NOT NULL UNIQUE",
  2200. "ALTER TABLE `vtiger_users` MODIFY COLUMN `is_admin` VARCHAR(3) DEFAULT '0'",
  2201. "ALTER TABLE `vtiger_users` MODIFY COLUMN `description` TEXT",
  2202. "ALTER TABLE `vtiger_users` MODIFY COLUMN `user_preferences` TEXT",
  2203. "ALTER TABLE `vtiger_users` MODIFY COLUMN `homeorder` VARCHAR(255) DEFAULT 'ALVT,PLVT,QLTQ,CVLVT,HLT,OLV,GRT,OLTSO,ILTI,MNL'",
  2204. "ALTER TABLE `vtiger_users` ADD COLUMN `currency_id` INTEGER(19) NOT NULL DEFAULT '1'",
  2205. "ALTER TABLE `vtiger_users` ADD COLUMN `defhomeview` VARCHAR(100) DEFAULT 'home_metrics'",
  2206. //"ALTER TABLE `vtiger_users2group` MODIFY COLUMN `groupid` INTEGER(19) NOT NULL PRIMARY KEY",
  2207. //"ALTER TABLE `vtiger_users2group` MODIFY COLUMN `userid` INTEGER(19) NOT NULL PRIMARY KEY",
  2208. "ALTER TABLE `vtiger_users_seq` MODIFY COLUMN `id` INTEGER(11) NOT NULL",
  2209. "ALTER TABLE `vtiger_vendor` MODIFY COLUMN `street` TEXT",
  2210. "ALTER TABLE `vtiger_vendor` MODIFY COLUMN `description` TEXT",
  2211. //"ALTER TABLE `vtiger_wordtemplates` MODIFY COLUMN `templateid` INTEGER(19) NOT NULL PRIMARY KEY",
  2212. //"ALTER TABLE `vtiger_wordtemplates` MODIFY COLUMN `description` TEXT",
  2213. "ALTER TABLE `vtiger_activity` ADD KEY `status1` (`status`, `eventstatus`)",
  2214. "ALTER TABLE `vtiger_attachments` ADD KEY `attachmentsid1` (`attachmentsid`)",
  2215. "ALTER TABLE `vtiger_blocks` ADD KEY `block_tabid` (`tabid`)",
  2216. "ALTER TABLE `vtiger_carrier` DROP INDEX `carrier_UK0`",
  2217. "ALTER TABLE `vtiger_carrier` ADD UNIQUE KEY `carrier_carrier_idx` (`carrier`)",
  2218. "ALTER TABLE `vtiger_contactgrouprelation` ADD KEY `contactgrouprelation_IDX1` (`groupname`)",
  2219. "ALTER TABLE `vtiger_def_org_field` ADD KEY `tabid4` (`tabid`)",
  2220. "ALTER TABLE `vtiger_def_org_share` ADD KEY `fk_def_org_share23` (`permission`)",
  2221. "ALTER TABLE `vtiger_field` ADD KEY `tabid2` (`tabid`)",
  2222. "ALTER TABLE `vtiger_field` ADD KEY `blockid` (`block`)",
  2223. "ALTER TABLE `vtiger_field` ADD KEY `displaytypeid` (`displaytype`)",
  2224. "ALTER TABLE `vtiger_group2grouprel` ADD KEY `fk_group2grouprel2` (`containsgroupid`)",
  2225. "ALTER TABLE `vtiger_group2role` ADD KEY `fk_group2role2` (`roleid`)",
  2226. "ALTER TABLE `vtiger_group2rs` ADD KEY `fk_group2rs2` (`roleandsubid`)",
  2227. "ALTER TABLE `vtiger_groups` ADD KEY `idx_groups_123group` (`groupname`)",
  2228. "ALTER TABLE `vtiger_invoice` ADD KEY `SoPo_IDX` (`invoiceid`)",
  2229. "ALTER TABLE `vtiger_invoice` ADD KEY `fk_Invoice2` (`salesorderid`)",
  2230. "ALTER TABLE `vtiger_invoicegrouprelation` ADD KEY `invoicegrouprelation_IDX1` (`groupname`, `invoiceid`)",
  2231. "ALTER TABLE `vtiger_leadgrouprelation` ADD KEY `leadgrouprelation_IDX0` (`leadid`)",
  2232. "ALTER TABLE `vtiger_moduleowners` ADD KEY `moduleowners_UK11` (`tabid`, `user_id`)",
  2233. //"ALTER TABLE `vtiger_org_share_action2tab` ADD KEY `fk_org_share_action2tab12345` (`tabid`)",
  2234. "ALTER TABLE `vtiger_ownernotify` ADD KEY `ownernotify_UK1` (`crmid`, `flag`)",
  2235. "ALTER TABLE `vtiger_parenttab` ADD KEY `parenttab_UK1` (`parenttabid`, `parenttab_label`, `visible`)",
  2236. "ALTER TABLE `vtiger_parenttabrel` ADD KEY `parenttabrelUK01` (`tabid`, `parenttabid`)",
  2237. "ALTER TABLE `vtiger_pogrouprelation` ADD KEY `pogrouprelation_IDX1` (`groupname`, `purchaseorderid`)",
  2238. "ALTER TABLE `vtiger_portal` ADD KEY `portal_UK01` (`portalname`)",
  2239. "ALTER TABLE `vtiger_potential` ADD KEY `potentialid1` (`potentialid`)",
  2240. "ALTER TABLE `vtiger_potentialgrouprelation` ADD KEY `potentialgrouprelation_IDX1` (`groupname`)",
  2241. "ALTER TABLE `vtiger_potstagehistory` DROP INDEX PotStageHistory_IDX1",
  2242. "ALTER TABLE `vtiger_potstagehistory` ADD INDEX `PotStageHistory_IDX1` (`historyid`)",
  2243. "ALTER TABLE `vtiger_potstagehistory` ADD KEY `fk_PotStageHistory` (`potentialid`)",
  2244. "ALTER TABLE `vtiger_profile2field` ADD KEY `tabid3` (`tabid`, `profileid`)",
  2245. //"ALTER TABLE `vtiger_profile2globalpermissions` ADD KEY `idx_profile2globalpermissions` (`profileid`, `globalactionid`)",
  2246. "ALTER TABLE `vtiger_profile2standardpermissions` ADD KEY `idx_prof2stad` (`profileid`, `tabid`, `Operation`)",
  2247. "ALTER TABLE `vtiger_profile2utility` ADD KEY `idx_prof2utility` (`profileid`, `tabid`, `activityid`)",
  2248. "ALTER TABLE `vtiger_purchaseorder` ADD KEY `PO_Vend_IDX` (`vendorid`)",
  2249. "ALTER TABLE `vtiger_purchaseorder` ADD KEY `PO_Quote_IDX` (`quoteid`)",
  2250. "ALTER TABLE `vtiger_purchaseorder` ADD KEY `PO_Contact_IDX` (`contactid`)",
  2251. "ALTER TABLE `vtiger_quotegrouprelation` ADD KEY `quotegrouprelation_IDX1` (`groupname`)",
  2252. //"ALTER TABLE `vtiger_quotes` DROP INDEX vtiger_quotestage",
  2253. "ALTER TABLE `vtiger_quotes` ADD INDEX `quotestage` (`quoteid`)",
  2254. "ALTER TABLE `vtiger_quotes` ADD KEY `potentialid2` (`potentialid`)",
  2255. "ALTER TABLE `vtiger_quotes` ADD KEY `contactid` (`contactid`)",
  2256. "ALTER TABLE `vtiger_recurringtype` ADD UNIQUE KEY `RecurringEvent_UK0` (`recurringtype`)",
  2257. "ALTER TABLE `vtiger_role2profile` ADD KEY `idx_role2profileid1` (`roleid`, `profileid`)",
  2258. "ALTER TABLE `vtiger_salesorder` ADD KEY `SoVend_IDX` (`vendorid`)",
  2259. "ALTER TABLE `vtiger_salesorder` ADD KEY `SoContact_IDX` (`contactid`)",
  2260. "ALTER TABLE `vtiger_seattachmentsrel` ADD KEY `attachmentsid2` (`attachmentsid`, `crmid`)",
  2261. "ALTER TABLE `vtiger_selectquery` ADD KEY `selectquery_IDX0` (`queryid`)",
  2262. "ALTER TABLE `vtiger_sogrouprelation` ADD KEY `sogrouprelation_IDX1` (`groupname`)",
  2263. "ALTER TABLE `vtiger_tab` ADD KEY `tabid1` (`tabid`)",
  2264. "ALTER TABLE `vtiger_taxclass` ADD UNIQUE KEY `taxclass_carrier_idx` (`taxclass`)",
  2265. "ALTER TABLE `vtiger_troubletickets` ADD KEY `status2` (`status`)",
  2266. "ALTER TABLE `vtiger_users2group` ADD KEY `idx_users2group` (`groupid`, `userid`)",
  2267. "ALTER TABLE `vtiger_users2group` ADD KEY `fk_users2group2` (`userid`)",
  2268. "ALTER TABLE `vtiger_customaction` ADD CONSTRAINT `customaction_FK1` FOREIGN KEY (`cvid`) REFERENCES `vtiger_customview` (`cvid`) ON DELETE CASCADE",
  2269. "ALTER TABLE `vtiger_profile2globalpermissions` ADD CONSTRAINT `fk_profile2globalpermissions57` FOREIGN KEY (`profileid`) REFERENCES `vtiger_profile` (`profileid`) ON DELETE CASCADE",
  2270. "ALTER TABLE `vtiger_invoice` ADD CONSTRAINT `fk_Invoice2` FOREIGN KEY (`salesorderid`) REFERENCES `vtiger_salesorder` (`salesorderid`) ON DELETE CASCADE",
  2271. "ALTER TABLE `vtiger_purchaseorder` ADD CONSTRAINT `fk_PO3` FOREIGN KEY (`contactid`) REFERENCES `vtiger_contactdetails` (`contactid`) ON DELETE CASCADE",
  2272. "ALTER TABLE `vtiger_purchaseorder` ADD CONSTRAINT `fk_PO2` FOREIGN KEY (`vendorid`) REFERENCES `vtiger_vendor` (`vendorid`) ON DELETE CASCADE",
  2273. "ALTER TABLE `vtiger_purchaseorder` ADD CONSTRAINT `fk_PO2345` FOREIGN KEY (`quoteid`) REFERENCES `vtiger_quotes` (`quoteid`) ON DELETE CASCADE",
  2274. "ALTER TABLE `vtiger_quotes` ADD CONSTRAINT `fk_Quotes3` FOREIGN KEY (`contactid`) REFERENCES `vtiger_contactdetails` (`contactid`) ON DELETE CASCADE",
  2275. "ALTER TABLE `vtiger_quotes` ADD CONSTRAINT `fk_Quotes2` FOREIGN KEY (`potentialid`) REFERENCES `vtiger_potential` (`potentialid`) ON DELETE CASCADE",
  2276. "ALTER TABLE `vtiger_salesorder` ADD CONSTRAINT `fk_SO4` FOREIGN KEY (`contactid`) REFERENCES `vtiger_contactdetails` (`contactid`) ON DELETE CASCADE",
  2277. "ALTER TABLE `vtiger_salesorder` ADD CONSTRAINT `fk_SO2` FOREIGN KEY (`vendorid`) REFERENCES `vtiger_vendor` (`vendorid`) ON DELETE CASCADE",
  2278. "ALTER TABLE `vtiger_vendorcontactrel` ADD CONSTRAINT `fk_VendorContactRel45` FOREIGN KEY (`vendorid`) REFERENCES `vtiger_vendor` (`vendorid`) ON DELETE CASCADE"
  2279. );
  2280. foreach($query_array as $query)
  2281. {
  2282. //Execute($query);
  2283. //These above array queries will not make any problems if failed to execute. whereas the user get confused if it fails. so we are not goiong to display these queries if it is executed successfully or not
  2284. $conn->query($query);
  2285. }
  2286. //First check whether this table is exist and the proceed
  2287. $currency_columns = $conn->getColumnNames("vtiger_currency_info");
  2288. if(!is_array($currency_columns))
  2289. {
  2290. $currency_query = "CREATE TABLE `vtiger_currency_info` (
  2291. `id` int(11) NOT NULL auto_increment,
  2292. `currency_name` varchar(100) default NULL,
  2293. `currency_code` varchar(100) default NULL,
  2294. `currency_symbol` varchar(30) default NULL,
  2295. `conversion_rate` decimal(10,3) default NULL,
  2296. `currency_status` varchar(25) default NULL,
  2297. `defaultid` varchar(10) NOT NULL default '0',
  2298. PRIMARY KEY (`id`)
  2299. ) ENGINE=InnoDB";
  2300. Execute($currency_query);
  2301. }
  2302. elseif(!in_array("id",$currency_columns))
  2303. {
  2304. $currency_query_array = Array(
  2305. "alter table vtiger_currency_info drop primary key",
  2306. "alter table vtiger_currency_info add column id int(11) NOT NULL auto_increment primary key FIRST",
  2307. "alter table vtiger_currency_info add column conversion_rate decimal(10,3) default NULL",
  2308. "alter table vtiger_currency_info add column currency_status varchar(25) default NULL",
  2309. "alter table vtiger_currency_info add column defaultid varchar(10) NOT NULL default '0'",
  2310. );
  2311. foreach($currency_query_array as $query)
  2312. {
  2313. Execute($query);
  2314. }
  2315. }
  2316. $migrationlog->debug("Database Modifications for 5.0(Alpha) Dev 3 ==> 5.0 Alpha (5) ends here.");
  2317. /************************* The following changes have been made after 5.0 Alpha 5 *************************/
  2318. $migrationlog->debug("Database Modifications after 5.0(Alpha 5) starts here.");
  2319. //Added on 22-04-06 - to add the Notify Owner vtiger_field in Contacts and Accounts
  2320. $newfieldid = $conn->getUniqueID("vtiger_field");
  2321. $insert_query = "insert into vtiger_field values (4, $newfieldid, 'notify_owner','contactdetails',1,56,'notify_owner','Notify Owner',1,0,0,10,24,4,1,'C~O',1,NULL,'ADV')";
  2322. Execute($insert_query);
  2323. populateFieldForSecurity('4',$newfieldid);
  2324. $newfieldid = $conn->getUniqueID("vtiger_field");
  2325. $insert_query = "insert into vtiger_field values (6, $newfieldid, 'notify_owner','account',1,56,'notify_owner','Notify Owner',1,0,0,10,18,9,1,'C~O',1,NULL,'ADV')";
  2326. Execute($insert_query);
  2327. populateFieldForSecurity('6',$newfieldid);
  2328. $notify_owner_array = Array(
  2329. "update vtiger_field set sequence=26 where tabid=4 and fieldname='modifiedtime'",
  2330. "update vtiger_field set sequence=25 where tabid=4 and fieldname='createdtime'",
  2331. //"insert into vtiger_field values(4,".$conn->getUniqueID("vtiger_field").",'notify_owner','contactdetails',1,56,'notify_owner','Notify Owner',1,0,0,10,24,4,1,'C~O',1,NULL,'ADV')",
  2332. "alter table vtiger_contactdetails add column notify_owner varchar(3) default 0 after reference",
  2333. "update vtiger_field set sequence=21 where tabid=6 and fieldname='modifiedtime'",
  2334. "update vtiger_field set sequence=20 where tabid=6 and fieldname='createdtime'",
  2335. "update vtiger_field set sequence=19 where tabid=6 and fieldname='assigned_user_id'",
  2336. //"insert into vtiger_field values(6,".$conn->getUniqueID("vtiger_field").",'notify_owner','account',1,56,'notify_owner','Notify Owner',1,0,0,10,18,9,1,'C~O',1,NULL,'ADV')",
  2337. "alter table vtiger_account add column notify_owner varchar(3) default 0 after emailoptout"
  2338. );
  2339. foreach($notify_owner_array as $query)
  2340. {
  2341. Execute($query);
  2342. }
  2343. //Added for RSS entries
  2344. $newfieldid = $conn->getUniqueID("vtiger_field");
  2345. $rss_insert_query = "insert into vtiger_field values (24, $newfieldid, 'rsscategory','rss',1,'15','rsscategory','rsscategory',1,0,0,255,13,null,1,'V~O',1,null,'BAS')";
  2346. Execute($rss_insert_query);
  2347. populateFieldForSecurity('24',$newfieldid);
  2348. //Quick Create Feature added for Vendor & PriceBook
  2349. $quickcreate_query = Array(
  2350. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 1 WHERE tabid = 18 and fieldname = 'vendorname'",
  2351. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 2 WHERE tabid = 18 and fieldname = 'phone'",
  2352. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 3 WHERE tabid = 18 and fieldname = 'email'",
  2353. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 1 WHERE tabid = 19 and fieldname = 'bookname'",
  2354. "UPDATE vtiger_field SET quickcreate = 0,quickcreatesequence = 2 WHERE tabid = 19 and fieldname = 'active'"
  2355. );
  2356. foreach($quickcreate_query as $query)
  2357. {
  2358. Execute($query);
  2359. }
  2360. //Added on 24-04-06 to populate vtiger_customview All for Campaign and webmails modules
  2361. $cvid1 = $conn->getUniqueID("vtiger_customview");
  2362. $cvid2 = $conn->getUniqueID("vtiger_customview");
  2363. $customview_query_array = Array(
  2364. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$cvid1.",'All',1,0,'Campaigns')",
  2365. "insert into vtiger_cvcolumnlist (cvid,columnindex,columnname) values (".$cvid1.",0,'vtiger_campaign:campaignname:campaignname:Campaigns_Campaign_Name:V')",
  2366. "insert into vtiger_cvcolumnlist (cvid,columnindex,columnname) values (".$cvid1.",1,'vtiger_campaign:campaigntype:campaigntype:Campaigns_Campaign_Type:N')",
  2367. "insert into vtiger_cvcolumnlist (cvid,columnindex,columnname) values (".$cvid1.",2,'vtiger_campaign:campaignstatus:campaignstatus:Campaigns_Campaign_Status:N')",
  2368. "insert into vtiger_cvcolumnlist (cvid,columnindex,columnname) values (".$cvid1.",3,'vtiger_campaign:expectedrevenue:expectedrevenue:Campaigns_Expected_Revenue:V')",
  2369. "insert into vtiger_cvcolumnlist (cvid,columnindex,columnname) values (".$cvid1.",4,'vtiger_campaign:closingdate:closingdate:Campaigns_Expected_Close_Date:D')",
  2370. "insert into vtiger_cvcolumnlist (cvid,columnindex,columnname) values (".$cvid1.",5,'vtiger_crmentity:smownerid:assigned_user_id:Campaigns_Assigned_To:V')",
  2371. "insert into vtiger_customview(cvid,viewname,setdefault,setmetrics,entitytype) values(".$cvid2.",'All',1,0,'Webmails')",
  2372. "insert into vtiger_cvcolumnlist (cvid,columnindex,columnname) values (".$cvid2.",0,'subject:subject:subject:Subject:V')",
  2373. "insert into vtiger_cvcolumnlist (cvid,columnindex,columnname) values (".$cvid2.",1,'from:fromname:fromname:From:N')",
  2374. "insert into vtiger_cvcolumnlist (cvid,columnindex,columnname) values (".$cvid2.",2,'to:tpname:toname:To:N')",
  2375. "insert into vtiger_cvcolumnlist (cvid,columnindex,columnname) values (".$cvid2.",3,'body:body:body:Body:V')"
  2376. );
  2377. foreach($customview_query_array as $query)
  2378. {
  2379. Execute($query);
  2380. }
  2381. $query_array2 = Array(
  2382. //"INSERT INTO vtiger_parenttabrel VALUES(2,4,2)",
  2383. //"INSERT INTO vtiger_parenttabrel VALUES(2,6,3)",
  2384. "update vtiger_cvcolumnlist set columnname ='vtiger_crmentity:smownerid:assigned_user_id:Emails_Sender:V' where columnname='vtiger_crmentity:smownerid:assigned_user_id:Emails_Assigned_To:V'",
  2385. "update vtiger_field set sequence = 2 where columnname='filename' and tablename = 'vtiger_attachments'",
  2386. "delete from vtiger_cvcolumnlist where columnname = 'vtiger_seactivityrel:crmid:parent_id:Emails_Related_To:I'",
  2387. //"update vtiger_cvcolumnlist set columnindex = 1 where cvid=20 and columnindex=3",
  2388. "update vtiger_field set info_type='ADV' where tabid=18 and columnname in ('street','pobox','city','state','postalcode','country','description')",
  2389. "update vtiger_field set info_type='ADV' where tabid in (20,21,22,23) and columnname in ('description','terms_conditions')",
  2390. "create table vtiger_inventorytaxinfo (taxid int(3) NOT NULL, taxname varchar(50) default NULL, taxlabel varchar(50) default NULL, percentage decimal(7,3) default NULL, deleted int(1) default 0, PRIMARY KEY (taxid), KEY vtiger_inventorytaxinfo_taxname_idx (taxname))",
  2391. "create table vtiger_producttaxrel ( productid int(11) NOT NULL, taxid int(3) NOT NULL, taxpercentage decimal(7,3) default NULL, KEY vtiger_producttaxrel_productid_idx (productid), KEY vtiger_producttaxrel_taxid_idx (taxid))",
  2392. "alter table vtiger_producttaxrel ADD CONSTRAINT fk_1_vtiger_producttaxrel FOREIGN KEY (productid) REFERENCES vtiger_products(productid) ON DELETE CASCADE",
  2393. "update vtiger_field set uitype=83, tablename='vtiger_producttaxrel' where tabid=14 and fieldname='taxclass'",
  2394. "insert into vtiger_moduleowners values(".$this->localGetTabID('Campaigns').",1)",
  2395. "alter table vtiger_attachments add column path varchar(255) default NULL"
  2396. );
  2397. foreach($query_array2 as $query)
  2398. {
  2399. Execute($query);
  2400. }
  2401. //This code will retrieve all the attachments from db and write it in a file
  2402. $attach_query_result = $conn->query("select vtiger_crmentity.createdtime, vtiger_attachments.* from vtiger_attachments inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_attachments.attachmentsid");
  2403. $noof_attachments = $conn->num_rows($attach_query_result);
  2404. for($attach_count = 0;$attach_count < $noof_attachments ;$attach_count++)
  2405. {
  2406. $attach_id = $conn->query_result($attach_query_result,$attach_count,'attachmentsid');
  2407. $attach_name = $conn->query_result($attach_query_result,$attach_count,'name');
  2408. $attach_data = $conn->query_result($attach_query_result,$attach_count,'attachmentcontents');
  2409. $created_time = $conn->query_result($attach_query_result,$attach_count,'createdtime');
  2410. //$filepath = decideFilePath();
  2411. //Added to set the file path where to store the file based on the created time
  2412. $date = explode(" ",$created_time);
  2413. $date_details = explode("-",$date[0]);
  2414. $year = $date_details[0];
  2415. $month = $date_details[1];
  2416. $day = $date_details[2];
  2417. //this is used to convert the month from number to string ie., 03 - March, 04 - April, etc.,
  2418. $month = date("F", mktime(0, 0, 0, $month, $day, $year));
  2419. $week_no = floor(($day-1)/7)+1;//decide the week ie., 1-7 = week1, 8-14=week2, 15-21=week3, etc.,
  2420. $week = "week".$week_no;
  2421. $filepath = 'storage/';
  2422. if(!is_dir($filepath.$year))
  2423. mkdir($filepath.$year);
  2424. if(!is_dir($filepath.$year."/".$month))
  2425. mkdir($filepath."$year/$month");
  2426. if(!is_dir($filepath.$year."/".$month."/".$week))
  2427. mkdir($filepath."$year/$month/$week");
  2428. $filepath = $filepath.$year."/".$month."/".$week."/";
  2429. $migrationlog->debug("File Path = $filepath");
  2430. //upto this added to set the file path based on attachment created time
  2431. //In this file name (attachmentid_filename) the file will be stored in the harddisk
  2432. $moved_filename = $attach_id."_".$attach_name;
  2433. //write the contents in the file
  2434. $handle = @fopen($filepath.$moved_filename,'w');
  2435. fputs($handle, base64_decode($attach_data));
  2436. fclose($handle);
  2437. //update the path in the db
  2438. $update_attach = Execute("update vtiger_attachments set path='".$filepath."' where attachmentsid=$attach_id");
  2439. }
  2440. //Before drop these fields we had read the contents of the file from db and wrote it in a file.
  2441. $alter_query_array = Array(
  2442. "alter table vtiger_attachments drop column attachmentsize",
  2443. "alter table vtiger_attachments drop column attachmentcontents"
  2444. );
  2445. foreach($alter_query_array as $query)
  2446. {
  2447. Execute($query);
  2448. }
  2449. //To populate the comboStrings for Campaigns module which are added newly
  2450. require_once('include/ComboStrings.php');
  2451. global $combo_strings;
  2452. $comboTables = Array('campaigntype','campaignstatus','expectedresponse');
  2453. foreach ($comboTables as $tablename)
  2454. {
  2455. $values = $combo_strings[$tablename."_dom"];
  2456. $i=0;
  2457. foreach ($values as $val => $cal)
  2458. {
  2459. if($val != '')
  2460. {
  2461. $conn->query("insert into vtiger_".$tablename. " values(null,'".$val."',".$i.",1)");
  2462. }
  2463. else
  2464. {
  2465. $conn->query("insert into vtiger_".$tablename. " values(null,'--None--',".$i.",1)");
  2466. }
  2467. $i++;
  2468. }
  2469. }
  2470. $update_query3 = "update vtiger_currency_info set conversion_rate=1, currency_status='Active', defaultid='-11' where id=1";
  2471. Execute($update_query3);
  2472. $update_query4 = "update vtiger_relatedlists set label='Purchase Order' where tabid=18 and name='get_purchase_orders'";
  2473. Execute($update_query4);
  2474. //Added on 27-05-06
  2475. $create_query27 = "CREATE TABLE vtiger_invitees (activityid int(19) NOT NULL, inviteeid int(19) NOT NULL, PRIMARY KEY (activityid,inviteeid))";
  2476. Execute($create_query27);
  2477. $alter_query_array17 = Array(
  2478. "ALTER TABLE vtiger_users ADD column hour_format varchar(30) default 'am/pm' AFTER date_format",
  2479. "ALTER TABLE vtiger_users ADD column start_hour varchar(30) default '10:00' AFTER hour_format",
  2480. "ALTER TABLE vtiger_users ADD column end_hour varchar(30) default '23:00' AFTER start_hour"
  2481. );
  2482. foreach($alter_query_array17 as $query)
  2483. {
  2484. Execute($query);
  2485. }
  2486. $create_query28 = "CREATE TABLE vtiger_emaildetails (
  2487. emailid int(19) NOT NULL,
  2488. from_email varchar(50) NOT NULL default '',
  2489. to_email text,
  2490. cc_email text,
  2491. bcc_email text,
  2492. assigned_user_email varchar(50) NOT NULL default '',
  2493. idlists varchar(50) NOT NULL default '',
  2494. email_flag varchar(50) NOT NULL default '',
  2495. PRIMARY KEY (`emailid`)
  2496. )";
  2497. Execute($create_query28);
  2498. $obj_array = Array('Leads'=>'vtiger_leaddetails','Contacts'=>'vtiger_contactdetails');
  2499. $leadfieldid = $conn->query_result($conn->query("select fieldid from vtiger_field where tabid=7 and fieldname='email'"),0,'fieldid');
  2500. $contactfieldid = $conn->query_result($conn->query("select fieldid from vtiger_field where tabid=4 and fieldname='email'"),0,'fieldid');
  2501. $fieldid_array = Array("Leads"=>"$leadfieldid","Contacts"=>"$contactfieldid");
  2502. $idname_array = Array("Leads"=>"leadid","Contacts"=>"contactid");
  2503. $query = 'select * from vtiger_seactivityrel where activityid in (select activityid from vtiger_activity where activitytype="Emails") group by activityid';
  2504. $result = $conn->query($query);
  2505. $numofrows = $conn->num_rows($result);
  2506. for($i=0;$i<$numofrows;$i++)
  2507. {
  2508. $toemail = "";
  2509. $idlists = '';
  2510. $emailid = $conn->query_result($result,$i,'activityid');
  2511. $result1 = $conn->query("select * from vtiger_seactivityrel where activityid = $emailid");
  2512. while($row = $conn->fetch_array($result1))
  2513. {
  2514. $result2 = $conn->query("select setype from vtiger_crmentity where crmid=".$row['crmid']);
  2515. $module = $conn->query_result($result2,0,'setype');
  2516. $idlists .= $row['crmid']."@$fieldid_array[$module]|";
  2517. if($module == 'Leads' || $module == 'Contacts')
  2518. {
  2519. $result3 = $conn->query("select lastname, firstname, email from $obj_array[$module] where $idname_array[$module] = ".$row['crmid']);
  2520. $toemail .= $conn->query_result($result3,0,'lastname')." ".$conn->query_result($result3,0,'firstname')."<".$conn->query_result($result3,0,'email').">###";
  2521. }
  2522. else
  2523. {
  2524. //the parent is not a Lead or Contact. so we have avoided the insert query
  2525. }
  2526. }
  2527. //insert this idlists and toemail values in vtiger_emaildetails table
  2528. $sql = "insert into vtiger_emaildetails values ($emailid,'',\"$toemail\",'','','',\"$idlists\",'SAVE')";
  2529. Execute($sql);
  2530. }
  2531. $update_query5 = "update vtiger_field set quickcreate=1, quickcreatesequence=NULL where tabid in (10,14)";
  2532. Execute($update_query5);
  2533. //Security vtiger_profile and vtiger_tab table handling by DON starts
  2534. $sql_sec="select profileid from vtiger_profile";
  2535. $result_sec=$conn->query($sql_sec);
  2536. $num_rows=$conn->num_rows($result_sec);
  2537. for($i=0;$i<$num_rows;$i++)
  2538. {
  2539. $prof_id=$conn->query_result($result_sec,$i,'profileid');
  2540. $sql1_sec="insert into vtiger_profile2utility values(".$prof_id.",13,8,0)";
  2541. Execute($sql1_sec);
  2542. $sql2_sec="insert into vtiger_profile2utility values(".$prof_id.",7,9,0)";
  2543. Execute($sql2_sec);
  2544. $sql3_sec="insert into vtiger_profile2tab values(".$prof_id.",26,0)";
  2545. Execute($sql3_sec);
  2546. $sql4_sec="insert into vtiger_profile2tab values(".$prof_id.",27,0)";
  2547. Execute($sql4_sec);
  2548. $sql7_sec="insert into vtiger_profile2standardpermissions values(".$prof_id.",26,0,0)";
  2549. Execute($sql7_sec);
  2550. $sql8_sec="insert into vtiger_profile2standardpermissions values(".$prof_id.",26,1,0)";
  2551. Execute($sql8_sec);
  2552. $sql9_sec="insert into vtiger_profile2standardpermissions values(".$prof_id.",26,2,0)";
  2553. Execute($sql9_sec);
  2554. $sql10_sec="insert into vtiger_profile2standardpermissions values(".$prof_id.",26,3,0)";
  2555. Execute($sql10_sec);
  2556. $sql11_sec="insert into vtiger_profile2standardpermissions values(".$prof_id.",26,4,0)";
  2557. Execute($sql11_sec);
  2558. }
  2559. //Inserting into vtiger_tab tables
  2560. $sec2="INSERT INTO vtiger_tab VALUES (27,'Portal',0,24,'Portal',null,null,1)";
  2561. $sec3="INSERT INTO vtiger_tab VALUES (28,'Webmails',0,25,'Webmails',null,null,1)";
  2562. //Insert into vtiger_def_org_share tables
  2563. $sec4="insert into vtiger_def_org_share values (".$conn->getUniqueID('vtiger_def_org_share').",26,2,0)";
  2564. Execute($sec2);
  2565. Execute($sec3);
  2566. Execute($sec4);
  2567. //Inserting into datashare related modules table
  2568. Execute("insert into vtiger_datashare_relatedmodules_seq values(1)");
  2569. //Lead Related Module
  2570. Execute("insert into vtiger_datashare_relatedmodules values (".$conn->getUniqueID('vtiger_datashare_relatedmodules').",7,10)");
  2571. //Account Related Module
  2572. Execute("insert into vtiger_datashare_relatedmodules values (".$conn->getUniqueID('vtiger_datashare_relatedmodules').",6,2)");
  2573. Execute("insert into vtiger_datashare_relatedmodules values (".$conn->getUniqueID('vtiger_datashare_relatedmodules').",6,13)");
  2574. Execute("insert into vtiger_datashare_relatedmodules values (".$conn->getUniqueID('vtiger_datashare_relatedmodules').",6,20)");
  2575. Execute("insert into vtiger_datashare_relatedmodules values (".$conn->getUniqueID('vtiger_datashare_relatedmodules').",6,22)");
  2576. Execute("insert into vtiger_datashare_relatedmodules values (".$conn->getUniqueID('vtiger_datashare_relatedmodules').",6,23)");
  2577. Execute("insert into vtiger_datashare_relatedmodules values (".$conn->getUniqueID('vtiger_datashare_relatedmodules').",6,10)");
  2578. //Potential Related Module
  2579. Execute("insert into vtiger_datashare_relatedmodules values (".$conn->getUniqueID('vtiger_datashare_relatedmodules').",2,20)");
  2580. Execute("insert into vtiger_datashare_relatedmodules values (".$conn->getUniqueID('vtiger_datashare_relatedmodules').",2,22)");
  2581. //Quote Related Module
  2582. Execute("insert into vtiger_datashare_relatedmodules values (".$conn->getUniqueID('vtiger_datashare_relatedmodules').",20,22)");
  2583. //SO Related Module
  2584. Execute("insert into vtiger_datashare_relatedmodules values (".$conn->getUniqueID('vtiger_datashare_relatedmodules').",22,23)");
  2585. //By Don Ends
  2586. //Added the vtiger_tabel vtiger_mail_accounts which has been added by mmbrich
  2587. $alter_query18 = "alter table vtiger_mail_accounts add column int_mailer int(1) default '0'";
  2588. Execute($alter_query18);
  2589. $update_query_array5 = Array(
  2590. "update vtiger_field set info_type='BAS' where tabid=6 and fieldname in ('tickersymbol','account_id')",
  2591. "update vtiger_relatedlists set label = 'Activity History' where tabid in (4,6,7,20,21,22,23) and label = 'History'",
  2592. "update vtiger_relatedlists set label = 'Products' where tabid=2 and name='get_products' and label='History'",
  2593. "update vtiger_relatedlists set label = 'Activity History' where tabid=2 and name='get_history' and label='History'"
  2594. );
  2595. foreach($update_query_array5 as $query)
  2596. {
  2597. Execute($query);
  2598. }
  2599. $insert_query_array27 = Array(
  2600. "insert into vtiger_relatedlists values(".$conn->getUniqueID('vtiger_relatedlists').",13,0,'get_ticket_history',3,'Ticket History',0)",
  2601. "insert into vtiger_parenttabrel values (2,10,4)",
  2602. "insert into vtiger_parenttabrel values (4,10,7)"
  2603. );
  2604. foreach($insert_query_array27 as $query)
  2605. {
  2606. Execute($query);
  2607. }
  2608. //User fields added in field table
  2609. $user_query_array = Array(
  2610. "alter table vtiger_users add column confirm_password varchar(50)",
  2611. "insert into vtiger_tab values (29,'Users',0,26,'Users',null,null,1)",
  2612. "insert into vtiger_blocks values (79,29,'LBL_USERLOGIN_ROLE',1,0,0,0,0,0)",
  2613. "insert into vtiger_blocks values (80,29,'LBL_MORE_INFORMATION',2,0,0,0,0,0)",
  2614. "insert into vtiger_blocks values (81,29,'LBL_ADDRESS_INFORMATION',3,0,0,0,0,0)",
  2615. );
  2616. foreach($user_query_array as $query)
  2617. {
  2618. Execute($query);
  2619. }
  2620. $newfieldid = $conn->getUniqueID("vtiger_field");
  2621. $insert_query = "insert into vtiger_field values (29, $newfieldid, 'user_name','vtiger_users',1,'106','user_name','User Name',1,0,0,11,1,79,1,'V~M',1,null,'BAS')";
  2622. Execute($insert_query);
  2623. populateFieldForSecurity('29',$newfieldid);
  2624. $newfieldid = $conn->getUniqueID("vtiger_field");
  2625. $insert_query = "insert into vtiger_field values (29, $newfieldid, 'is_admin','vtiger_users',1,'156','is_admin','Admin',1,0,0,3,2,79,1,'V~O',1,null,'BAS')";
  2626. Execute($insert_query);
  2627. populateFieldForSecurity('29',$newfieldid);
  2628. $newfieldid = $conn->getUniqueID("vtiger_field");
  2629. $insert_query = "insert into vtiger_field values (29, $newfieldid, 'user_password','vtiger_users',1,'99','user_password','Password',1,0,0,30,3,79,4,'P~M',1,null,'BAS')";
  2630. Execute($insert_query);
  2631. populateFieldForSecurity('29',$newfieldid);
  2632. $newfieldid = $conn->getUniqueID("vtiger_field");
  2633. $insert_query = "insert into vtiger_field values (29, $newfieldid, 'confirm_password','vtiger_users',1,'99','confirm_password','Confirm Password',1,0,0,30,4,79,4,'P~M',1,null,'BAS')";
  2634. Execute($insert_query);
  2635. populateFieldForSecurity('29',$newfieldid);
  2636. $newfieldid = $conn->getUniqueID("vtiger_field");
  2637. $insert_query = "insert into vtiger_field values (29, $newfieldid,'first_name','vtiger_users',1,'1','first_name','First Name',1,0,0,30,5,79,1,'V~O',1,null,'BAS')";
  2638. Execute($insert_query);
  2639. populateFieldForSecurity('29',$newfieldid);
  2640. $newfieldid = $conn->getUniqueID("vtiger_field");
  2641. $insert_query = "insert into vtiger_field values (29, $newfieldid,'last_name','vtiger_users',1,'2','last_name','Last Name',1,0,0,30,6,79,1,'V~M',1,null,'BAS')";
  2642. Execute($insert_query);
  2643. populateFieldForSecurity('29',$newfieldid);
  2644. $newfieldid = $conn->getUniqueID("vtiger_field");
  2645. $insert_query = "insert into vtiger_field values (29, $newfieldid,'roleid','vtiger_user2role',1,'98','roleid','Role',1,0,0,200,7,79,1,'V~M',1,null,'BAS')";
  2646. Execute($insert_query);
  2647. populateFieldForSecurity('29',$newfieldid);
  2648. $newfieldid = $conn->getUniqueID("vtiger_field");
  2649. $insert_query = "insert into vtiger_field values (29, $newfieldid,'email1','vtiger_users',1,'104','email1','Email',1,0,0,100,9,79,1,'E~M',1,null,'BAS')";
  2650. Execute($insert_query);
  2651. populateFieldForSecurity('29',$newfieldid);
  2652. $newfieldid = $conn->getUniqueID("vtiger_field");
  2653. $insert_query = "insert into vtiger_field values (29, $newfieldid,'status','vtiger_users',1,'115','status','Status',1,0,0,100,10,79,1,'V~O',1,null,'BAS')";
  2654. Execute($insert_query);
  2655. populateFieldForSecurity('29',$newfieldid);
  2656. $newfieldid = $conn->getUniqueID("vtiger_field");
  2657. $insert_query = "insert into vtiger_field values (29, $newfieldid,'activity_view','vtiger_users',1,'15','activity_view','Default Activity View',1,0,0,100,13,79,1,'V~O',1,null,'BAS')";
  2658. Execute($insert_query);
  2659. populateFieldForSecurity('29',$newfieldid);
  2660. $newfieldid = $conn->getUniqueID("vtiger_field");
  2661. $insert_query = "insert into vtiger_field values (29, $newfieldid,'lead_view','vtiger_users',1,'15','lead_view','Default Lead View',1,0,0,100,12,79,1,'V~O',1,null,'BAS')";
  2662. Execute($insert_query);
  2663. populateFieldForSecurity('29',$newfieldid);
  2664. $newfieldid = $conn->getUniqueID("vtiger_field");
  2665. $insert_query = "insert into vtiger_field values (29, $newfieldid,'currency_id','vtiger_users',1,'116','currency_id','Currency',1,0,0,100,11,79,1,'I~O',1,null,'BAS')";
  2666. Execute($insert_query);
  2667. populateFieldForSecurity('29',$newfieldid);
  2668. $newfieldid = $conn->getUniqueID("vtiger_field");
  2669. $insert_query = "insert into vtiger_field values (29, $newfieldid,'title','vtiger_users',1,'1','title','Title',1,0,0,50,1,80,1,'V~O',1,null,'BAS')";
  2670. Execute($insert_query);
  2671. populateFieldForSecurity('29',$newfieldid);
  2672. $newfieldid = $conn->getUniqueID("vtiger_field");
  2673. $insert_query = "insert into vtiger_field values (29, $newfieldid,'phone_work','vtiger_users',1,'1','phone_work','Office Phone',1,0,0,50,2,80,1,'V~O',1,null,'BAS')";
  2674. Execute($insert_query);
  2675. populateFieldForSecurity('29',$newfieldid);
  2676. $newfieldid = $conn->getUniqueID("vtiger_field");
  2677. $insert_query = "insert into vtiger_field values (29, $newfieldid,'department','vtiger_users',1,'1','department','Department',1,0,0,50,3,80,1,'V~O',1,null,'BAS')";
  2678. Execute($insert_query);
  2679. populateFieldForSecurity('29',$newfieldid);
  2680. $newfieldid = $conn->getUniqueID("vtiger_field");
  2681. $insert_query = "insert into vtiger_field values (29, $newfieldid,'phone_mobile','vtiger_users',1,'1','phone_mobile','Mobile',1,0,0,50,4,80,1,'V~O',1,null,'BAS')";
  2682. Execute($insert_query);
  2683. populateFieldForSecurity('29',$newfieldid);
  2684. $newfieldid = $conn->getUniqueID("vtiger_field");
  2685. $insert_query = "insert into vtiger_field values (29, $newfieldid,'reports_to_id','vtiger_users',1,'101','reports_to_id','Reports To',1,0,0,50,5,80,1,'V~O',1,null,'BAS')";
  2686. Execute($insert_query);
  2687. populateFieldForSecurity('29',$newfieldid);
  2688. $newfieldid = $conn->getUniqueID("vtiger_field");
  2689. $insert_query = "insert into vtiger_field values (29, $newfieldid,'phone_other','vtiger_users',1,'1','phone_other','Other Phone',1,0,0,50,5,80,1,'V~O',1,null,'BAS')";
  2690. Execute($insert_query);
  2691. populateFieldForSecurity('29',$newfieldid);
  2692. $newfieldid = $conn->getUniqueID("vtiger_field");
  2693. $insert_query = "insert into vtiger_field values (29, $newfieldid,'email2','vtiger_users',1,'13','email2','Other Email',1,0,0,100,6,80,1,'E~O',1,null,'BAS')";
  2694. Execute($insert_query);
  2695. populateFieldForSecurity('29',$newfieldid);
  2696. $newfieldid = $conn->getUniqueID("vtiger_field");
  2697. $insert_query = "insert into vtiger_field values (29, $newfieldid,'phone_fax','vtiger_users',1,'1','phone_fax','Fax',1,0,0,50,7,80,1,'V~O',1,null,'BAS')";
  2698. Execute($insert_query);
  2699. populateFieldForSecurity('29',$newfieldid);
  2700. $newfieldid = $conn->getUniqueID("vtiger_field");
  2701. $insert_query = "insert into vtiger_field values (29, $newfieldid,'yahoo_id','vtiger_users',1,'13','yahoo_id','Yahoo id',1,0,0,100,7,80,1,'E~O',1,null,'BAS')";
  2702. Execute($insert_query);
  2703. populateFieldForSecurity('29',$newfieldid);
  2704. $newfieldid = $conn->getUniqueID("vtiger_field");
  2705. $insert_query = "insert into vtiger_field values (29, $newfieldid,'phone_home','vtiger_users',1,'1','phone_home','Home Phone',1,0,0,50,8,80,1,'V~O',1,null,'BAS')";
  2706. Execute($insert_query);
  2707. populateFieldForSecurity('29',$newfieldid);
  2708. $newfieldid = $conn->getUniqueID("vtiger_field");
  2709. $insert_query = "insert into vtiger_field values (29, $newfieldid,'imagename','vtiger_users',1,'105','imagename','User Image',1,0,0,250,9,80,1,'V~O',1,null,'BAS')";
  2710. Execute($insert_query);
  2711. populateFieldForSecurity('29',$newfieldid);
  2712. $newfieldid = $conn->getUniqueID("vtiger_field");
  2713. $insert_query = "insert into vtiger_field values (29, $newfieldid,'date_format','vtiger_users',1,'15','date_format','Date Format',1,0,0,30,10,80,1,'V~O',1,null,'BAS')";
  2714. Execute($insert_query);
  2715. populateFieldForSecurity('29',$newfieldid);
  2716. $newfieldid = $conn->getUniqueID("vtiger_field");
  2717. $insert_query = "insert into vtiger_field values (29, $newfieldid,'tagcloud','vtiger_users',1,'103','tagcloud','Tag Cloud',1,0,0,250,13,80,1,'V~O',1,null,'BAS')";
  2718. Execute($insert_query);
  2719. populateFieldForSecurity('29',$newfieldid);
  2720. $newfieldid = $conn->getUniqueID("vtiger_field");
  2721. $insert_query = "insert into vtiger_field values (29, $newfieldid,'signature','vtiger_users',1,'21','signature','Signature',1,0,0,250,11,80,1,'V~O',1,null,'BAS')";
  2722. Execute($insert_query);
  2723. populateFieldForSecurity('29',$newfieldid);
  2724. $newfieldid = $conn->getUniqueID("vtiger_field");
  2725. $insert_query = "insert into vtiger_field values (29, $newfieldid,'description','vtiger_users',1,'21','description','Notes',1,0,0,250,12,80,1,'V~O',1,null,'BAS')";
  2726. Execute($insert_query);
  2727. populateFieldForSecurity('29',$newfieldid);
  2728. $newfieldid = $conn->getUniqueID("vtiger_field");
  2729. $insert_query = "insert into vtiger_field values (29, $newfieldid,'address_street','vtiger_users',1,'21','address_street','Street Address',1,0,0,250,1,81,1,'V~O',1,null,'BAS')";
  2730. Execute($insert_query);
  2731. populateFieldForSecurity('29',$newfieldid);
  2732. $newfieldid = $conn->getUniqueID("vtiger_field");
  2733. $insert_query = "insert into vtiger_field values (29, $newfieldid,'address_city','vtiger_users',1,'1','address_city','City',1,0,0,100,2,81,1,'V~O',1,null,'BAS')";
  2734. Execute($insert_query);
  2735. populateFieldForSecurity('29',$newfieldid);
  2736. $newfieldid = $conn->getUniqueID("vtiger_field");
  2737. $insert_query = "insert into vtiger_field values (29, $newfieldid,'address_state','vtiger_users',1,'1','address_state','State',1,0,0,100,3,81,1,'V~O',1,null,'BAS')";
  2738. Execute($insert_query);
  2739. populateFieldForSecurity('29',$newfieldid);
  2740. $newfieldid = $conn->getUniqueID("vtiger_field");
  2741. $insert_query = "insert into vtiger_field values (29, $newfieldid,'address_postalcode','vtiger_users',1,'1','address_postalcode','Postal Code',1,0,0,100,4,81,1,'V~O',1,null,'BAS')";
  2742. Execute($insert_query);
  2743. populateFieldForSecurity('29',$newfieldid);
  2744. $newfieldid = $conn->getUniqueID("vtiger_field");
  2745. $insert_query = "insert into vtiger_field values (29, $newfieldid,'address_country','vtiger_users',1,'1','address_country','Country',1,0,0,100,5,81,1,'V~O',1,null,'BAS')";
  2746. Execute($insert_query);
  2747. populateFieldForSecurity('29',$newfieldid);
  2748. $create_query29 = "CREATE TABLE vtiger_status (
  2749. `statusid` int(19) NOT NULL auto_increment,
  2750. `status` varchar(200) NOT NULL,
  2751. `sortorderid` int(19) NOT NULL default '0',
  2752. `presence` int(1) NOT NULL default '1',
  2753. PRIMARY KEY (`statusid`)
  2754. )";
  2755. Execute($create_query29);
  2756. Execute("insert into vtiger_status values (1,'Active',0,1)");
  2757. Execute("insert into vtiger_status values (2,'Inactive',1,1)");
  2758. $create_query30 = "CREATE TABLE vtiger_activity_view (
  2759. `activity_viewid` int(19) NOT NULL auto_increment,
  2760. `activity_view` varchar(200) NOT NULL,
  2761. `sortorderid` int(19) NOT NULL default '0',
  2762. `presence` int(1) NOT NULL default '1',
  2763. PRIMARY KEY (`activity_viewid`)
  2764. )";
  2765. Execute($create_query30);
  2766. Execute("insert into vtiger_activity_view values (1,'Today',0,1)");
  2767. Execute("insert into vtiger_activity_view values (2,'This Week',1,1)");
  2768. Execute("insert into vtiger_activity_view values (3,'This Month',2,1)");
  2769. Execute("insert into vtiger_activity_view values (4,'This Year',3,1)");
  2770. $create_query31 = "CREATE TABLE vtiger_lead_view (
  2771. `lead_viewid` int(19) NOT NULL auto_increment,
  2772. `lead_view` varchar(200) NOT NULL,
  2773. `sortorderid` int(19) NOT NULL default '0',
  2774. `presence` int(1) NOT NULL default '1',
  2775. PRIMARY KEY (`lead_viewid`)
  2776. )";
  2777. Execute($create_query31);
  2778. Execute("insert into vtiger_lead_view values (1,'Today',0,1)");
  2779. Execute("insert into vtiger_lead_view values (2,'Last 2 Days',1,1)");
  2780. Execute("insert into vtiger_lead_view values (3,'Last Week',2,1)");
  2781. $create_query32 = "CREATE TABLE vtiger_date_format (
  2782. `date_formatid` int(19) NOT NULL auto_increment,
  2783. `date_format` varchar(200) NOT NULL,
  2784. `sortorderid` int(19) NOT NULL default '0',
  2785. `presence` int(1) NOT NULL default '1',
  2786. PRIMARY KEY (`date_formatid`)
  2787. )";
  2788. Execute($create_query32);
  2789. Execute("insert into vtiger_date_format values (1,'dd-mm-yyyy',0,1)");
  2790. Execute("insert into vtiger_date_format values (2,'mm-dd-yyyy',1,1)");
  2791. Execute("insert into vtiger_date_format values (3,'yyyy-mm-dd',2,1)");
  2792. //end of User fields added in field table
  2793. //Activities and Leads Added under Marketing
  2794. Execute("insert into vtiger_parenttabrel values (2,7,5)");
  2795. Execute("insert into vtiger_parenttabrel values (2,9,6)");
  2796. Execute("insert into vtiger_parenttabrel values (4,9,8)");
  2797. //Queries to remove the rss categories
  2798. Execute("drop table vtiger_rsscategory");
  2799. Execute("delete from vtiger_field where tabid=24");
  2800. //Added on 23-06-06
  2801. $newfieldid = $conn->getUniqueID("vtiger_field");
  2802. $query = "insert into vtiger_field values (29, $newfieldid, 'hour_format','vtiger_users',1,'116','hour_format','Calendar Hour Format',1,0,0,100,13,79,3,'I~O',1,null,'BAS')";
  2803. Execute($query);
  2804. populateFieldForSecurity('29',$newfieldid);
  2805. $newfieldid = $conn->getUniqueID("vtiger_field");
  2806. $query = "insert into vtiger_field values (29, $newfieldid, 'end_hour','vtiger_users',1,'116','end_hour','Day ends at',1,0,0,100,15,79,3,'I~O',1,null,'BAS')";
  2807. Execute($query);
  2808. populateFieldForSecurity('29',$newfieldid);
  2809. $newfieldid = $conn->getUniqueID("vtiger_field");
  2810. $query = "insert into vtiger_field values (29, $newfieldid, 'start_hour','vtiger_users',1,'116','start_hour','Day starts at',1,0,0,100,14,79,3,'I~O',1,null,'BAS')";
  2811. Execute($query);
  2812. populateFieldForSecurity('29',$newfieldid);
  2813. Execute("insert into vtiger_relatedlists values (".$conn->getUniqueID('vtiger_relatedlists').",".getTabid("Campaigns").",".getTabid("Potentials").",'get_opportunities',3,'Potentials',0)");
  2814. Execute("insert into vtiger_relatedlists values(".$conn->getUniqueID('vtiger_relatedlists').",".getTabid("Campaigns").",9,'get_activities',4,'Activities',0)");
  2815. $newfieldid = $conn->getUniqueID("vtiger_field");
  2816. $query = "insert into vtiger_field values (2, $newfieldid, 'campaignid','vtiger_potential',1,'58','campaignid','Campaign Source',1,0,0,100,12,1,1,'N~O',1,null,'BAS')";
  2817. Execute($query);
  2818. populateFieldForSecurity('2',$newfieldid);
  2819. //Added on 28-06-06
  2820. //Campaigns module added in Leads and Contacts RelatedList
  2821. Execute("insert into vtiger_relatedlists values(".$conn->getUniqueID('vtiger_relatedlists').",".getTabid("Leads").",".getTabid("Campaigns").",'get_campaigns',6,'Campaigns',0)");
  2822. Execute("insert into vtiger_relatedlists values(".$conn->getUniqueID('vtiger_relatedlists').",".getTabid("Contacts").",".getTabid("Campaigns").",'get_campaigns',11,'Campaigns',0)");
  2823. //Contact Name has been removed from Events Information
  2824. Execute("delete from vtiger_field where tabid=16 and fieldname='contact_id'");
  2825. //queries to resequence the fields
  2826. $fieldname=array('eventstatus','sendnotification','activitytype','location','createdtime','modifiedtime','taskpriority','notime','visibility');
  2827. $tablename=array('vtiger_activity','vtiger_activity','vtiger_activity','vtiger_activity','vtiger_crmentity','vtiger_crmentity','vtiger_activity','vtiger_activity','vtiger_activity');
  2828. $sequence = array(10,11,12,13,14,15,16,17,18);
  2829. for($j = 0;$j < 9;$j++)
  2830. {
  2831. Execute("update vtiger_field set sequence=".$sequence[$j]." where tablename='".$tablename[$j]."' && fieldname='".$fieldname[$j]."' and tabid=16");
  2832. }
  2833. //Campaign has been removed from field table
  2834. Execute("delete from vtiger_field where tabid=7 and fieldname='campaignid'");
  2835. Execute("delete from vtiger_field where tabid=4 and fieldname='campaignid'");
  2836. //Query added to have Calendar under Marketing and Support
  2837. $conn->query("insert into vtiger_parenttabrel values (2,17,7)");
  2838. $conn->query("insert into vtiger_parenttabrel values (4,17,9)");
  2839. //Added on 02-08-2006 ie., 2nd August 2006
  2840. //column added for proxy server settings
  2841. Execute("alter table vtiger_systems add column server_port int(19) default NULL after server");
  2842. //type changed to support decimal places
  2843. Execute("alter table vtiger_campaign change expectedrevenue expectedrevenue decimal(11,3)");
  2844. Execute("alter table vtiger_campaign change budgetcost budgetcost decimal(11,3)");
  2845. Execute("alter table vtiger_campaign change actualcost actualcost decimal(11,3)");
  2846. Execute("alter table vtiger_campaign change expectedroi expectedroi decimal(11,3)");
  2847. Execute("alter table vtiger_campaign change actualroi actualroi decimal(11,3)");
  2848. //homeorder value modified to get graph in homepage
  2849. Execute("update vtiger_users set homeorder='ALVT,PLVT,QLTQ,CVLVT,HLT,OLV,GRT,OLTSO,ILTI,MNL,HDB'");
  2850. //Removed activities from product related list
  2851. Execute("delete from vtiger_relatedlists where tabid = 14 and related_tabid=9");
  2852. Execute("insert into vtiger_relatedlists values(".$conn->getUniqueID('vtiger_relatedlists').",".getTabid("HelpDesk").",9,'get_history',4,'Activity History',0)");
  2853. //Assigned to field for Events made Optional
  2854. Execute("update vtiger_field set typeofdata='V~M' where columnname='smownerid' and tabid=16 and fieldname='assigned_user_id'");
  2855. //Query added to have Notes under Marketing and Support --Jeri -- 04-06-06
  2856. Execute("insert into vtiger_parenttabrel values (2,8,8)");
  2857. //Update Query for quickcreate sequence of Campaign & Ticket -- Added by Ahmed -- 11-07-2006
  2858. Execute("update vtiger_field set quickcreatesequence='3' where fieldname='filename' and tabid=13");
  2859. Execute("update vtiger_field set quickcreatesequence='4' where fieldname='ticketpriorities' and tabid=13");
  2860. Execute("update vtiger_field set quickcreatesequence='3' where fieldname='campaigntype' and tabid=26");
  2861. Execute("update vtiger_field set quickcreatesequence='6' where fieldname='campaignstatus' and tabid=26");
  2862. Execute("update vtiger_field set quickcreatesequence='2' where fieldname='closingdate' and tabid=26");
  2863. //Added for Tax and Inventory - Product details handling
  2864. Execute("CREATE TABLE vtiger_inventoryproductrel (id int(19) NOT NULL, productid int(19) NOT NULL, sequence_no int(4) NOT NULL default 1, quantity int(19) default NULL, listprice decimal(11,3) default NULL, discount_percent decimal(7,3) default NULL, discount_amount decimal(11,3) default NULL, comment varchar(100) default NULL, KEY inventoryproductrel_id_idx (id), KEY inventoryproductrel_productid_idx (productid) ) ENGINE=InnoDB");
  2865. //Execute("alter table vtiger_inventorytaxinfo add column deleted int(1) default 0");
  2866. Execute("CREATE TABLE vtiger_shippingtaxinfo ( taxid int(3) NOT NULL, taxname varchar(50) default NULL, taxlabel varchar(50) default NULL, percentage decimal(7,3) default NULL, deleted int(1) default '0', PRIMARY KEY (taxid), KEY shippingtaxinfo_taxname_idx (taxname) ) ENGINE=InnoDB");
  2867. Execute("CREATE TABLE vtiger_inventoryshippingrel (id int(19) NOT NULL, KEY inventoryishippingrel_id_idx (id) ) ENGINE=InnoDB");
  2868. $newfieldid = $conn->getUniqueID("vtiger_field");
  2869. $query = "insert into vtiger_field values (21, $newfieldid, 'taxtype','vtiger_purchaseorder',1,'15','hdnTaxType','Tax Type',1,0,0,100,14,57,3,'V~O',1,null,'BAS')";
  2870. Execute($query);
  2871. populateFieldForSecurity('21',$newfieldid);
  2872. $newfieldid = $conn->getUniqueID("vtiger_field");
  2873. $query = "insert into vtiger_field values (21, $newfieldid, 'discount_percent','vtiger_purchaseorder',1,'1','hdnDiscountPercent','Discount Percent',1,0,0,100,14,57,3,'N~O',1,null,'BAS')";
  2874. Execute($query);
  2875. populateFieldForSecurity('21',$newfieldid);
  2876. $newfieldid = $conn->getUniqueID("vtiger_field");
  2877. $query = "insert into vtiger_field values (21, $newfieldid, 'discount_amount','vtiger_purchaseorder',1,'1','hdnDiscountAmount','Discount Amount',1,0,0,100,14,57,3,'N~O',1,null,'BAS')";
  2878. Execute($query);
  2879. populateFieldForSecurity('21',$newfieldid);
  2880. $newfieldid = $conn->getUniqueID("vtiger_field");
  2881. $query = "insert into vtiger_field values (21, $newfieldid, 's_h_amount','vtiger_purchaseorder',1,'1','hdnS_H_Amount','S&H Amount',1,0,0,100,14,57,3,'N~O',1,null,'BAS')";
  2882. Execute($query);
  2883. populateFieldForSecurity('21',$newfieldid);
  2884. $newfieldid = $conn->getUniqueID("vtiger_field");
  2885. $query = "insert into vtiger_field values (22, $newfieldid, 'taxtype','vtiger_salesorder',1,'15','hdnTaxType','Tax Type',1,0,0,100,15,63,3,'V~O',1,null,'BAS')";
  2886. Execute($query);
  2887. populateFieldForSecurity('22',$newfieldid);
  2888. $newfieldid = $conn->getUniqueID("vtiger_field");
  2889. $query = "insert into vtiger_field values (22, $newfieldid, 'discount_percent','vtiger_salesorder',1,'1','hdnDiscountPercent','Discount Percent',1,0,0,100,15,63,3,'N~O',1,null,'BAS')";
  2890. Execute($query);
  2891. populateFieldForSecurity('22',$newfieldid);
  2892. $newfieldid = $conn->getUniqueID("vtiger_field");
  2893. $query = "insert into vtiger_field values (22, $newfieldid, 'discount_amount','vtiger_salesorder',1,'1','hdnDiscountAmount','Discount Amount',1,0,0,100,15,63,3,'N~O',1,null,'BAS')";
  2894. Execute($query);
  2895. populateFieldForSecurity('22',$newfieldid);
  2896. $newfieldid = $conn->getUniqueID("vtiger_field");
  2897. $query = "insert into vtiger_field values (22, $newfieldid, 's_h_amount','vtiger_salesorder',1,'1','hdnS_H_Amount','S&H Amount',1,0,0,100,15,63,3,'N~O',1,null,'BAS')";
  2898. Execute($query);
  2899. populateFieldForSecurity('22',$newfieldid);
  2900. $newfieldid = $conn->getUniqueID("vtiger_field");
  2901. $query = "insert into vtiger_field values (20, $newfieldid, 'taxtype','vtiger_quotes',1,'15','hdnTaxType','Tax Type',1,0,0,100,14,51,3,'V~O',1,null,'BAS')";
  2902. Execute($query);
  2903. populateFieldForSecurity('20',$newfieldid);
  2904. $newfieldid = $conn->getUniqueID("vtiger_field");
  2905. $query = "insert into vtiger_field values (20, $newfieldid, 'discount_percent','vtiger_quotes',1,'1','hdnDiscountPercent','Discount Percent',1,0,0,100,14,51,3,'N~O',1,null,'BAS')";
  2906. Execute($query);
  2907. populateFieldForSecurity('20',$newfieldid);
  2908. $newfieldid = $conn->getUniqueID("vtiger_field");
  2909. $query = "insert into vtiger_field values (20, $newfieldid, 'discount_amount','vtiger_quotes',1,'1','hdnDiscountAmount','Discount Amount',1,0,0,100,14,51,3,'N~O',1,null,'BAS')";
  2910. Execute($query);
  2911. populateFieldForSecurity('20',$newfieldid);
  2912. $newfieldid = $conn->getUniqueID("vtiger_field");
  2913. $query = "insert into vtiger_field values (20, $newfieldid, 's_h_amount','vtiger_quotes',1,'1','hdnS_H_Amount','S&H Amount',1,0,0,100,14,51,3,'N~O',1,null,'BAS')";
  2914. Execute($query);
  2915. populateFieldForSecurity('20',$newfieldid);
  2916. $newfieldid = $conn->getUniqueID("vtiger_field");
  2917. $query = "insert into vtiger_field values (23, $newfieldid, 'taxtype','vtiger_invoice',1,'15','hdnTaxType','Tax Type',1,0,0,100,13,69,3,'V~O',1,null,'BAS')";
  2918. Execute($query);
  2919. populateFieldForSecurity('23',$newfieldid);
  2920. $newfieldid = $conn->getUniqueID("vtiger_field");
  2921. $query = "insert into vtiger_field values (23, $newfieldid, 'discount_percent','vtiger_invoice',1,'1','hdnDiscountPercent','Discount Percent',1,0,0,100,13,69,3,'N~O',1,null,'BAS')";
  2922. Execute($query);
  2923. populateFieldForSecurity('23',$newfieldid);
  2924. $newfieldid = $conn->getUniqueID("vtiger_field");
  2925. $query = "insert into vtiger_field values (23, $newfieldid, 'discount_amount','vtiger_invoice',1,'1','hdnDiscountAmount','Discount Amount',1,0,0,100,13,69,3,'N~O',1,null,'BAS')";
  2926. Execute($query);
  2927. populateFieldForSecurity('23',$newfieldid);
  2928. $newfieldid = $conn->getUniqueID("vtiger_field");
  2929. $query = "insert into vtiger_field values (23, $newfieldid, 's_h_amount','vtiger_invoice',1,'1','hdnS_H_Amount','S&H Amount',1,0,0,100,14,57,3,'N~O',1,null,'BAS')";
  2930. Execute($query);
  2931. populateFieldForSecurity('23',$newfieldid);
  2932. Execute("alter table vtiger_purchaseorder add column taxtype varchar(25) default NULL after subtotal");
  2933. Execute("alter table vtiger_purchaseorder add column discount_percent decimal(11,3) default NULL after taxtype");
  2934. Execute("alter table vtiger_purchaseorder add column discount_amount decimal(11,3) default NULL after discount_percent");
  2935. Execute("alter table vtiger_purchaseorder add column s_h_amount decimal(11,3) default NULL after discount_amount");
  2936. Execute("alter table vtiger_salesorder add column taxtype varchar(25) default NULL after subtotal");
  2937. Execute("alter table vtiger_salesorder add column discount_percent decimal(11,3) default NULL after taxtype");
  2938. Execute("alter table vtiger_salesorder add column discount_amount decimal(11,3) default NULL after discount_percent");
  2939. Execute("alter table vtiger_salesorder add column s_h_amount decimal(11,3) default NULL after discount_amount");
  2940. Execute("alter table vtiger_quotes add column taxtype varchar(25) default NULL after total");
  2941. Execute("alter table vtiger_quotes add column discount_percent decimal(11,3) default NULL after taxtype");
  2942. Execute("alter table vtiger_quotes add column discount_amount decimal(11,3) default NULL after discount_percent");
  2943. Execute("alter table vtiger_quotes add column s_h_amount decimal(11,3) default NULL after discount_amount");
  2944. Execute("alter table vtiger_invoice add column taxtype varchar(25) default NULL after total");
  2945. Execute("alter table vtiger_invoice add column discount_percent decimal(11,3) default NULL after taxtype");
  2946. Execute("alter table vtiger_invoice add column discount_amount decimal(11,3) default NULL after discount_percent");
  2947. Execute("alter table vtiger_invoice add column s_h_amount decimal(11,3) default NULL after discount_amount");
  2948. //Update Query to Match Notes List View Header Fieldnames with Custom View combo values
  2949. Execute("update vtiger_field set fieldlabel='Title' where fieldlabel='Subject' and tabid=8");
  2950. Execute("update vtiger_field set fieldlabel='File' where fieldlabel='Attachment' and tabid=8");
  2951. //Update Query to change the UI type of Rating Field in Accounts Module from 1 to 15 to display combo list
  2952. Execute("update vtiger_field set uitype=15 where tabid=6 and fieldname='rating'");
  2953. //Insert and Update Query for new block addition for Campaigns Module
  2954. Execute("update vtiger_blocks set blocklabel='LBL_EXPECTATIONS_AND_ACTUALS' where tabid=26 and blockid=78");
  2955. Execute("insert into vtiger_blocks values (82,26,'LBL_DESCRIPTION_INFORMATION',4,0,0,0,0,0)");
  2956. //Update Query for rearrangements of fields in Campaigns Module's Detail/Edit/Create View
  2957. Execute("update vtiger_field set sequence=1 where tabid=26 and columnname='campaignname' and fieldname='campaignname'");
  2958. Execute("update vtiger_field set sequence=2 where tabid=26 and columnname='campaignstatus' and fieldname='campaignstatus'");
  2959. Execute("update vtiger_field set sequence=3 where tabid=26 and columnname='smownerid' and fieldname='assigned_user_id'");
  2960. Execute("update vtiger_field set sequence=4 where tabid=26 and columnname='product_id' and fieldname='product_id'");
  2961. Execute("update vtiger_field set sequence=5 where tabid=26 and columnname='campaigntype' and fieldname='campaigntype'");
  2962. Execute("update vtiger_field set sequence=6 where tabid=26 and columnname='closingdate' and fieldname='closingdate'");
  2963. Execute("update vtiger_field set sequence=7 where tabid=26 and columnname='targetaudience' and fieldname='targetaudience'");
  2964. Execute("update vtiger_field set sequence=8 where tabid=26 and columnname='targetsize' and fieldname='targetsize'");
  2965. Execute("update vtiger_field set sequence=9 where tabid=26 and columnname='sponsor' and fieldname='sponsor'");
  2966. Execute("update vtiger_field set sequence=10 where tabid=26 and columnname='numsent' and fieldname='numsent'");
  2967. Execute("update vtiger_field set sequence=11 where tabid=26 and columnname='createdtime' and fieldname='createdtime'");
  2968. Execute("update vtiger_field set sequence=12 where tabid=26 and columnname='modifiedtime' and fieldname='modifiedtime'");
  2969. Execute("update vtiger_field set sequence=1, block=78 where tabid=26 and columnname='budgetcost' and fieldname='budgetcost'");
  2970. Execute("update vtiger_field set sequence=2, block=78 where tabid=26 and columnname='actualcost' and fieldname='actualcost'");
  2971. Execute("update vtiger_field set sequence=3, block=78 where tabid=26 and columnname='expectedresponse' and fieldname='expectedresponse'");
  2972. Execute("update vtiger_field set sequence=4, block=78 where tabid=26 and columnname='expectedrevenue' and fieldname='expectedrevenue'");
  2973. Execute("update vtiger_field set sequence=5, block=78 where tabid=26 and columnname='expectedsalescount' and fieldname='expectedsalescount'");
  2974. Execute("update vtiger_field set sequence=6, block=78 where tabid=26 and columnname='actualsalescount' and fieldname='actualsalescount'");
  2975. Execute("update vtiger_field set sequence=7, block=78 where tabid=26 and columnname='expectedresponsecount' and fieldname='expectedresponsecount'");
  2976. Execute("update vtiger_field set sequence=8, block=78 where tabid=26 and columnname='actualresponsecount' and fieldname='actualresponsecount'");
  2977. Execute("update vtiger_field set sequence=9, block=78 where tabid=26 and columnname='expectedroi' and fieldname='expectedroi'");
  2978. Execute("update vtiger_field set sequence=10, block=78 where tabid=26 and columnname='actualroi' and fieldname='actualroi'");
  2979. //Update query to set the fieldname in user detail/edit/create view
  2980. Execute("update vtiger_field set sequence=1 where tabid=29 and columnname='user_name' and fieldname='user_name' and block=79");
  2981. Execute("update vtiger_field set sequence=2 where tabid=29 and columnname='is_admin' and fieldname='is_admin' and block=79");
  2982. Execute("update vtiger_field set sequence=3 where tabid=29 and columnname='user_password' and fieldname='user_password' and block=79");
  2983. Execute("update vtiger_field set sequence=4 where tabid=29 and columnname='email1' and fieldname='email1' and block=79");
  2984. Execute("update vtiger_field set sequence=5 where tabid=29 and columnname='confirm_password' and fieldname='confirm_password' and block=79");
  2985. Execute("update vtiger_field set sequence=6 where tabid=29 and columnname='status' and fieldname='status' and block=79");
  2986. Execute("update vtiger_field set sequence=7 where tabid=29 and columnname='first_name' and fieldname='first_name' and block=79");
  2987. Execute("update vtiger_field set sequence=8 where tabid=29 and columnname='currency_id' and fieldname='currency_id' and block=79");
  2988. Execute("update vtiger_field set sequence=9 where tabid=29 and columnname='last_name' and fieldname='last_name' and block=79");
  2989. Execute("update vtiger_field set sequence=10 where tabid=29 and columnname='lead_view' and fieldname='lead_view' and block=79");
  2990. Execute("update vtiger_field set sequence=11 where tabid=29 and columnname='roleid' and fieldname='roleid' and block=79");
  2991. Execute("update vtiger_field set sequence=12 where tabid=29 and columnname='activity_view' and fieldname='activity_view' and block=79");
  2992. Execute("update vtiger_field set sequence=13 where tabid=29 and columnname='hour_format' and fieldname='hour_format' and block=79");
  2993. Execute("update vtiger_field set sequence=14 where tabid=29 and columnname='start_hour' and fieldname='start_hour' and block=79");
  2994. Execute("update vtiger_field set sequence=15 where tabid=29 and columnname='end_hour' and fieldname='end_hour' and block=79");
  2995. Execute("update vtiger_field set sequence=1 where tabid=29 and columnname='title' and fieldname='title' and block=80");
  2996. Execute("update vtiger_field set sequence=2 where tabid=29 and columnname='phone_fax' and fieldname='phone_fax' and block=80");
  2997. Execute("update vtiger_field set sequence=3 where tabid=29 and columnname='department' and fieldname='department' and block=80");
  2998. Execute("update vtiger_field set sequence=4 where tabid=29 and columnname='email2' and fieldname='email2' and block=80");
  2999. Execute("update vtiger_field set sequence=5 where tabid=29 and columnname='phone_work' and fieldname='phone_work' and block=80");
  3000. Execute("update vtiger_field set sequence=6 where tabid=29 and columnname='yahoo_id' and fieldname='yahoo_id' and block=80");
  3001. Execute("update vtiger_field set sequence=7 where tabid=29 and columnname='phone_mobile' and fieldname='phone_mobile' and block=80");
  3002. Execute("update vtiger_field set sequence=8 where tabid=29 and columnname='reports_to_id' and fieldname='reports_to_id' and block=80");
  3003. Execute("update vtiger_field set sequence=9 where tabid=29 and columnname='phone_home' and fieldname='phone_home' and block=80");
  3004. Execute("update vtiger_field set sequence=10 where tabid=29 and columnname='imagename' and fieldname='imagename' and block=80");
  3005. Execute("update vtiger_field set sequence=11 where tabid=29 and columnname='phone_other' and fieldname='phone_other' and block=80");
  3006. Execute("update vtiger_field set sequence=12 where tabid=29 and columnname='date_format' and fieldname='date_format' and block=80");
  3007. Execute("update vtiger_field set sequence=13 where tabid=29 and columnname='signature' and fieldname='signature' and block=80");
  3008. Execute("update vtiger_field set sequence=14 where tabid=29 and columnname='description' and fieldname='description' and block=80");
  3009. Execute("update vtiger_field set sequence=15 where tabid=29 and columnname='tagcloud' and fieldname='tagcloud' and block=80");
  3010. Execute("update vtiger_field set sequence=1 where tabid=29 and columnname='address_street' and fieldname='address_street' and block=81");
  3011. Execute("update vtiger_field set sequence=2 where tabid=29 and columnname='address_country' and fieldname='address_country' and block=81");
  3012. Execute("update vtiger_field set sequence=3 where tabid=29 and columnname='address_city' and fieldname='address_city' and block=81");
  3013. Execute("update vtiger_field set sequence=4 where tabid=29 and columnname='address_postalcode' and fieldname='address_postalcode' and block=81");
  3014. Execute("update vtiger_field set sequence=5 where tabid=29 and columnname='address_state' and fieldname='address_state' and block=81");
  3015. //Added for Recurring events
  3016. Execute("alter table vtiger_recurringevents add column recurringfreq int(19) default NULL");
  3017. Execute("alter table vtiger_recurringevents add column recurringinfo varchar(50) default NULL");
  3018. //Update Query for changing the uitype for existing picklist entries making it non-editable
  3019. Execute("update vtiger_field set uitype=111 where fieldname in ('sales_stage','ticketstatus','taskstatus','eventstatus','faqstatus','quotestage','postatus','sostatus','invoicestatus')");
  3020. //Inventory Tax handlings -- Starts
  3021. //Added to populate the default Shipping & Hanlding tax informations
  3022. $shvatid = $conn->getUniqueID("vtiger_shippingtaxinfo");
  3023. $shsalesid = $conn->getUniqueID("vtiger_shippingtaxinfo");
  3024. $shserviceid = $conn->getUniqueID("vtiger_shippingtaxinfo");
  3025. $conn->query("insert into vtiger_shippingtaxinfo values($shvatid,'shtax".$shvatid."','VAT','4.50','0')");
  3026. $conn->query("insert into vtiger_shippingtaxinfo values($shsalesid,'shtax".$shsalesid."','Sales','10.00','0')");
  3027. $conn->query("insert into vtiger_shippingtaxinfo values($shserviceid,'shtax".$shserviceid."','Service','12.50','0')");
  3028. //After added these taxes we should add these taxes as columns in vtiger_inventoryshippingrel table
  3029. $conn->query("alter table vtiger_inventoryshippingrel add column shtax$shvatid decimal(7,3) default NULL");
  3030. $conn->query("alter table vtiger_inventoryshippingrel add column shtax$shsalesid decimal(7,3) default NULL");
  3031. $conn->query("alter table vtiger_inventoryshippingrel add column shtax$shserviceid decimal(7,3) default NULL");
  3032. //Added to populate the Common tax which will be used to save the existing tax (percentage will be calculated based on the total tax amount retrieved from the entity tables of PO, SO, Quotes and Invoice)
  3033. $migratedtaxid = 1;
  3034. $migratedtaxid = $conn->getUniqueID("vtiger_inventorytaxinfo");
  3035. $migrated_taxname = "tax$migratedtaxid";
  3036. $conn->query("insert into vtiger_inventorytaxinfo values($migratedtaxid,'".$migrated_taxname."','Tax','0.00','0')");
  3037. //After added these taxes we should add these taxes as columns in vtiger_inventoryproductrel table
  3038. $conn->query("alter table vtiger_inventoryproductrel add column $migrated_taxname decimal(7,3) default NULL");
  3039. //Now we should create tax for each and every value given in picklist taxclass
  3040. $taxres = $conn->query("select * from vtiger_taxclass");
  3041. $taxcount = $conn->num_rows($taxres);
  3042. for($i=0;$i<$taxcount;$i++)
  3043. {
  3044. $taxlabel = $conn->query_result($taxres,$i,'taxclass');
  3045. $newtaxid = $conn->getUniqueID("vtiger_inventorytaxinfo");
  3046. $addtaxres = $conn->query("alter table vtiger_inventoryproductrel add column tax$newtaxid decimal(7,3) default NULL");
  3047. if($addtaxres)
  3048. $conn->query("insert into vtiger_inventorytaxinfo values($newtaxid,'tax".$newtaxid."','".$taxlabel."','0.00','0')");
  3049. }
  3050. //Finished the add tax process based on the available tax classes
  3051. //To save Product - Tax relationship
  3052. //get Product - taxclass and add entry in vtiger_producttaxrel for this product - tax relationship
  3053. $productres = $conn->query("select productid, taxclass from vtiger_products");
  3054. $productcount = $conn->num_rows($productres);
  3055. for($i=0;$i<$productcount;$i++)
  3056. {
  3057. $productid = $conn->query_result($productres,$i,'productid');
  3058. $taxlabel = $conn->query_result($productres,$i,'taxclass');
  3059. $taxres = $conn->query("select taxid from vtiger_inventorytaxinfo where taxlabel='".addslashes($taxlabel)."'");
  3060. $taxid = $conn->query_result($taxres,0,'taxid');
  3061. $taxquery = "insert into vtiger_producttaxrel values($productid, \"$taxid\", '0.00')";
  3062. //Execute($taxquery);
  3063. $conn->query($taxquery);
  3064. }
  3065. //Retrieve values from poproductrel, soproductrel, quotesproductrel, invoiceproductrel and store in vtiger_inventoryproductrel
  3066. $inventory_tables = Array(
  3067. 'vtiger_poproductrel'=>'purchaseorderid',
  3068. 'vtiger_soproductrel'=>'salesorderid',
  3069. 'vtiger_quotesproductrel'=>'quoteid',
  3070. 'vtiger_invoiceproductrel'=>'invoiceid'
  3071. );
  3072. foreach($inventory_tables as $tablename => $idname)
  3073. {
  3074. $res = $conn->query("select * from $tablename order by $idname");
  3075. $count = $conn->num_rows($res);
  3076. $id = $oldid = 0;
  3077. $seqno = 0;
  3078. for($i=0;$i<$count;$i++)
  3079. {
  3080. $oldid = $id;
  3081. $id = $conn->query_result($res,$i,$idname);
  3082. //for every new PO/SO/Quotes/Invoice entity we should set the sequence start value as 1
  3083. if($id != $oldid)
  3084. $seqno = 1;
  3085. $productid = $conn->query_result($res,$i,'productid');
  3086. $quantity = $conn->query_result($res,$i,'quantity');
  3087. $listprice = $conn->query_result($res,$i,'listprice');
  3088. $query1 = "insert into vtiger_inventoryproductrel(id,productid,sequence_no,quantity,listprice) values($id, $productid,$seqno, $quantity, $listprice)";
  3089. Execute($query1);
  3090. $seqno++;
  3091. }
  3092. }
  3093. //Now for each and every PO, SO, Quotes and Invoice we should get the total, discount, tax
  3094. $inventory_tables = Array(
  3095. 'vtiger_purchaseorder'=>'purchaseorderid',
  3096. 'vtiger_salesorder'=>'salesorderid',
  3097. 'vtiger_quotes'=>'quoteid',
  3098. 'vtiger_invoice'=>'invoiceid'
  3099. );
  3100. foreach($inventory_tables as $tablename => $idname)
  3101. {
  3102. $res2 = $conn->query("select * from $tablename order by $idname");
  3103. $entitycount = $conn->num_rows($res2);
  3104. for($i=0;$i<$entitycount;$i++)
  3105. {
  3106. $idval = $conn->query_result($res2,$i,$idname);
  3107. //$res3 = $conn->query("select * from $tablename where $idname=$idval");
  3108. $subtotal = $conn->query_result($res2,$i,'subtotal');
  3109. $taxamount = $conn->query_result($res2,$i,'salestax');
  3110. //Now based on the inventory tax total - calculate the percentage
  3111. $taxpercent = '0.00';
  3112. if($taxamount > 0 && $subtotal >0)
  3113. {
  3114. $taxpercent = $taxamount*100/$subtotal;
  3115. }
  3116. //update the taxtype as group
  3117. $query2 = "update $tablename set taxtype='group'";
  3118. Execute($query2);
  3119. //update the calculated percentage for the entity ie., PO/SO/Quotes/Invoice
  3120. $query3 = "update vtiger_inventoryproductrel set $migrated_taxname='".$taxpercent."' where id=$idval";
  3121. Execute($query3);
  3122. }
  3123. }
  3124. //we have retrieve and saved all the values, so we can delete the unwanted tables
  3125. Execute("drop table vtiger_poproductrel");
  3126. Execute("drop table vtiger_soproductrel");
  3127. Execute("drop table vtiger_quotesproductrel");
  3128. Execute("drop table vtiger_invoiceproductrel");
  3129. //Inventory Tax handlings -- Ends
  3130. //Add Inventory History tracking tables ie.,PO Status, SO Status, Quote Stage and Invoice Status tables
  3131. //PO Status
  3132. Execute("CREATE TABLE vtiger_postatushistory ( historyid int(19) NOT NULL auto_increment, purchaseorderid int(19) NOT NULL, vendorname varchar(100) default NULL, total decimal(10,0) default NULL, postatus varchar(200) default NULL, lastmodified datetime default NULL, PRIMARY KEY (historyid), KEY postatushistory_purchaseorderid_idx (purchaseorderid), CONSTRAINT fk_1_vtiger_postatushistory FOREIGN KEY (purchaseorderid) REFERENCES vtiger_purchaseorder (purchaseorderid) ON DELETE CASCADE ) ENGINE=InnoDB");
  3133. //SO Status
  3134. Execute("CREATE TABLE vtiger_sostatushistory (historyid int(19) NOT NULL auto_increment, salesorderid int(19) NOT NULL, accountname varchar(100) default NULL, total decimal(10,0) default NULL, sostatus varchar(200) default NULL, lastmodified datetime default NULL, PRIMARY KEY (historyid), KEY sostatushistory_salesorderid_idx (salesorderid), CONSTRAINT fk_1_vtiger_sostatushistory FOREIGN KEY (salesorderid) REFERENCES vtiger_salesorder (salesorderid) ON DELETE CASCADE ) ENGINE=InnoDB");
  3135. //Quote Stage
  3136. Execute("CREATE TABLE vtiger_quotestagehistory ( historyid int(19) NOT NULL auto_increment, quoteid int(19) NOT NULL, accountname varchar(100) default NULL, total decimal(10,0) default NULL, quotestage varchar(200) default NULL, lastmodified datetime default NULL, PRIMARY KEY (historyid), KEY quotestagehistory_quoteid_idx (quoteid), CONSTRAINT fk_1_vtiger_quotestagehistory FOREIGN KEY (quoteid) REFERENCES vtiger_quotes (quoteid) ON DELETE CASCADE) ENGINE=InnoDB");
  3137. //Invoice Status
  3138. Execute("CREATE TABLE vtiger_invoicestatushistory ( historyid int(19) NOT NULL auto_increment, invoiceid int(19) NOT NULL, accountname varchar(100) default NULL, total decimal(10,0) default NULL, invoicestatus varchar(200) default NULL, lastmodified datetime default NULL, PRIMARY KEY (historyid), KEY invoicestatushistory_invoiceid_idx (invoiceid), CONSTRAINT fk_1_vtiger_invoicestatushistory FOREIGN KEY (invoiceid) REFERENCES vtiger_invoice (invoiceid) ON DELETE CASCADE) ENGINE=InnoDB");
  3139. //User image handling
  3140. Execute("insert into vtiger_blocks values (83,29,'LBL_USER_IMAGE_INFORMATION',4,0,0,0,0,0)");
  3141. Execute("update vtiger_field set block=83 where tabid=29 and fieldname='imagename' and columnname='imagename'");
  3142. Execute("update vtiger_field set tablename='vtiger_products' where fieldname='taxclass' && tabid=14");
  3143. Execute("update vtiger_field set info_type='BAS' where tabid=4 and fieldname='email' and columnname='email'");
  3144. Execute("update vtiger_field set info_type='ADV' where tabid=4 and fieldname='otherphone' and columnname='otherphone'");
  3145. Execute("CREATE TABLE vtiger_salesmanattachmentsrel ( smid int(19) NOT NULL default '0', attachmentsid int(19) NOT NULL default '0', PRIMARY KEY (smid, attachmentsid), KEY salesmanattachmentsrel_smid_idx (smid), KEY salesmanattachmentsrel_attachmentsid_idx (attachmentsid), CONSTRAINT fk_1_vtiger_salesmanattachmentsrel FOREIGN KEY (smid) REFERENCES vtiger_users (id), CONSTRAINT fk_2_vtiger_salesmanattachmentsrel FOREIGN KEY (attachmentsid) REFERENCES vtiger_attachments (attachmentsid) ON DELETE CASCADE) ENGINE=InnoDB");
  3146. //Changes made for Activity merge with Calendar - Starts
  3147. Execute("alter table vtiger_activity add column time_end varchar(50) default NULL after time_start");
  3148. Execute("delete from vtiger_tab where tabid=17");
  3149. Execute("update vtiger_tab set name='Calendar',tablabel='Calendar' where tabid=9");
  3150. $newfieldid = $conn->getUniqueID("vtiger_field");
  3151. $query = "insert into vtiger_field values (9, $newfieldid, 'time_end','vtiger_activity', 1,'2','time_end','End Time',1,0,0,100,6,19,3,'T~O',1,null,'BAS')";
  3152. Execute($query);
  3153. populateFieldForSecurity('9',$newfieldid);
  3154. $newfieldid = $conn->getUniqueID("vtiger_field");
  3155. $query = "insert into vtiger_field values (16, $newfieldid, 'time_end','vtiger_activity', 1,'2','time_end','End Time',1,0,0,100,6,41,3,'T~M',1,null,'BAS')";
  3156. Execute($query);
  3157. populateFieldForSecurity('16',$newfieldid);
  3158. Execute("delete from vtiger_profile2tab where tabid=17");
  3159. Execute("delete from vtiger_org_share_action2tab where tabid=17");
  3160. Execute("delete from vtiger_def_org_share where tabid=17");
  3161. Execute("delete from vtiger_parenttabrel where tabid=17");
  3162. //Changes made for Activity merge with Calendar - Ends
  3163. //audit trial table
  3164. Execute("create table vtiger_audit_trial(auditid int(19) NOT NULL, userid int(19) default NULL, module varchar(255) default NULL, action varchar(255) default NULL, recordid varchar(20) default NULL, actiondate datetime default NULL, PRIMARY KEY (auditid)) ENGINE=InnoDB");
  3165. //Added after 5 rc release
  3166. Execute("alter table vtiger_account modify siccode varchar(50)");
  3167. Execute("update vtiger_field set typeofdata='V~O' where fieldname='siccode' and columnname='siccode' and tabid=6");
  3168. //changes made for CustomView and Reports - Activities changed to Calendar -- Starts
  3169. //Added to change the entitytype from Activities to Calendar for customview
  3170. Execute("update vtiger_crmentity set setype='Calendar' where setype='Activities'");
  3171. Execute("update vtiger_customview set entitytype='Calendar' where entitytype='Activities'");
  3172. //Added to change the primarymodule from Activities to Calendar for Reports
  3173. Execute("update vtiger_reportmodules set primarymodule='Calendar' where primarymodule='Activities'");
  3174. Execute("update vtiger_reportmodules set primarymodule='PurchaseOrder' where primarymodule='Orders'");
  3175. Execute("update vtiger_reportmodules set secondarymodules='PurchaseOrder' where secondarymodules='Orders'");
  3176. //we should change the Activities to Calendar in columnname values in customview and report related tables
  3177. $prefix = "vtiger_";
  3178. $change_cols_array = Array(
  3179. "cvcolumnlist"=>"columnname",
  3180. "cvstdfilter"=>"columnname",
  3181. "cvadvfilter"=>"columnname",
  3182. "selectcolumn"=>"columnname",
  3183. "relcriteria"=>"columnname",
  3184. "reportsortcol"=>"columnname",
  3185. "reportdatefilter"=>"datecolumnname",
  3186. "reportsummary"=>"columnname",
  3187. );
  3188. //This is to change Activities to Calendar
  3189. foreach($change_cols_array as $tablename => $columnname)
  3190. {
  3191. $result = $conn->query("select $columnname from $prefix$tablename where $columnname like \"%Activities%\"");
  3192. while($row = $conn->fetch_row($result))
  3193. {
  3194. if($row[$columnname] !='' && $row[$columnname] != 'none')
  3195. {
  3196. Execute("update $prefix$tablename set $columnname=\"".str_replace("Activities","Calendar",$row[$columnname])."\" where $columnname=\"$row[$columnname]\"");
  3197. }
  3198. }
  3199. }
  3200. //This is to change the Orders to PurchaseOrder
  3201. foreach($change_cols_array as $tablename => $columnname)
  3202. {
  3203. $result1 = $conn->query("select $columnname from $prefix$tablename where $columnname like \"%Orders%\"");
  3204. while($row1 = $conn->fetch_row($result1))
  3205. {
  3206. if($row1[$columnname] !='' && $row1[$columnname] != 'none')
  3207. {
  3208. Execute("update $prefix$tablename set $columnname=\"".str_replace("Orders","PurchaseOrder",$row1[$columnname])."\" where $columnname=\"$row1[$columnname]\"");
  3209. }
  3210. }
  3211. }
  3212. //we have to change the table name from activity to crmentity for customview activity description
  3213. Execute('update vtiger_cvcolumnlist set columnname="vtiger_crmentity:description:description:Calendar_Description:V" where columnname="vtiger_activity:description:description:Calendar_Description:V"');
  3214. //we have to change the table name (alias) from activity to crmentiryCalendar for reports activity description
  3215. Execute('update vtiger_selectcolumn set columnname="vtiger_crmentityCalendar:description:Calendar_Description:description:V" where columnname="vtiger_activity:description:Calendar_Description:description:V"');
  3216. //changes made for CustomView and Reports - Activities changed to Calendar -- Ends
  3217. Execute("update vtiger_field set uitype = 16 where tabid=2 and uitype=111 and columnname='sales_stage'");
  3218. Execute("update vtiger_field set quickcreate=1,quickcreatesequence=null where fieldname='duration_hours' and tabid=16");
  3219. Execute("update vtiger_field set quickcreate=0,quickcreatesequence=5 where fieldname='due_date' and tabid=16");
  3220. //we have to add id, sortorderid and presence in all existing custom field pick list tables.
  3221. $cf_picklist_res = $conn->query("select fieldname from vtiger_field where uitype=15 and fieldname like 'cf_%'");
  3222. $noofPicklists = $conn->num_rows($cf_picklist_res);
  3223. for($i=0;$i<$noofPicklists;$i++)
  3224. {
  3225. $fieldname = $conn->query_result($cf_picklist_res,$i,'fieldname');
  3226. $tablename = "vtiger_".$fieldname;
  3227. $idname = $fieldname."id";
  3228. $alterquery = "alter table $tablename add column $idname int(19) auto_increment PRIMARY KEY FIRST, add column sortorderid int(19) default 0 NOT NULL, add column presence int(1) default 1 NOT NULL";
  3229. Execute($alterquery);
  3230. }
  3231. $conn->query("alter table vtiger_organizationdetails drop primary key");
  3232. Execute("alter table vtiger_organizationdetails change column organizationame organizationname varchar(60) NOT NULL");
  3233. Execute("alter table vtiger_organizationdetails ADD PRIMARY KEY (organizationname)");
  3234. //Activity related changes
  3235. Execute('update vtiger_field set typeofdata="D~M~OTH~GE~date_start~Start Date & Time", uitype=23 where fieldname="due_date" and tabid=16');
  3236. Execute('update vtiger_field set uitype=53 where tabid=16 and fieldname="assigned_user_id"');
  3237. Execute('update vtiger_field set typeofdata="D~M~OTH~GE~date_start~Start Date & Time", uitype=23 where fieldname="due_date" and tabid=9');
  3238. Execute('update vtiger_field set uitype=53 where tabid=9 and fieldname="assigned_user_id"');
  3239. Execute("alter table vtiger_activity change column subject subject varchar(100) NOT NULL");
  3240. Execute("alter table vtiger_activity change column activitytype activitytype varchar(50) NOT NULL");
  3241. Execute("alter table vtiger_activity change column date_start date_start date NOT NULL");
  3242. Execute("alter table vtiger_activity change column time_start time_start varchar(50) default NULL");
  3243. //Execute("alter table vtiger_activity change column visibility visibility varchar(50) NOT NULL default 'all'");
  3244. Execute("delete from vtiger_field where tabid=14 and fieldname='currency'");
  3245. //Product related changes
  3246. Execute('update vtiger_field set typeofdata="D~O~OTH~GE~sales_start_date~Sales Start Date" where tabid=14 and fieldname="sales_end_date"');
  3247. Execute('update vtiger_field set typeofdata="D~O~OTH~GE~start_date~Start Date" where tabid=14 and fieldname="expiry_date"');
  3248. //changes related to Incoming mail server settings
  3249. Execute("alter table vtiger_mail_accounts drop column showbody");
  3250. //change the Account relatedlist Activity label from Acivities to Activities
  3251. Execute("update vtiger_relatedlists set label='Activities' where tabid=6 and relation_id=3");
  3252. //change the fieldname from title to notes_title for notes and update in columnlist also
  3253. Execute("update vtiger_field set fieldname='notes_title' where tabid=8 and fieldname='title'");
  3254. Execute('update vtiger_cvcolumnlist set columnname="vtiger_notes:title:notes_title:Notes_Title:V" where columnname="vtiger_notes:title:title:Notes_Title:V"');
  3255. //change the sequence of Billing and Shipping address details for Inventory modules
  3256. Execute("update vtiger_field set sequence=5 where tabid in (20,21,22,23) and fieldname='bill_city'");
  3257. Execute("update vtiger_field set sequence=6 where tabid in (20,21,22,23) and fieldname='ship_city'");
  3258. Execute("update vtiger_field set sequence=7 where tabid in (20,21,22,23) and fieldname='bill_state'");
  3259. Execute("update vtiger_field set sequence=8 where tabid in (20,21,22,23) and fieldname='ship_state'");
  3260. Execute("update vtiger_field set sequence=9 where tabid in (20,21,22,23) and fieldname='bill_code'");
  3261. Execute("update vtiger_field set sequence=10 where tabid in (20,21,22,23) and fieldname='ship_code'");
  3262. Execute("update vtiger_field set sequence=11 where tabid in (20,21,22,23) and fieldname='bill_country'");
  3263. Execute("update vtiger_field set sequence=12 where tabid in (20,21,22,23) and fieldname='ship_country'");
  3264. //for vtiger_campaignleadrel table
  3265. Execute("alter table vtiger_campaignleadrel DROP PRIMARY KEY");
  3266. Execute("alter table vtiger_campaignleadrel ADD PRIMARY KEY (campaignid,leadid)");
  3267. //for vtiger_campaigncontrel table
  3268. Execute("alter table vtiger_campaigncontrel DROP PRIMARY KEY");
  3269. Execute("alter table vtiger_campaigncontrel ADD PRIMARY KEY (campaignid,contactid)");
  3270. //for vtiger_seactivityrel table
  3271. Execute("alter table vtiger_seactivityrel DROP PRIMARY KEY");
  3272. Execute("alter table vtiger_seactivityrel ADD PRIMARY KEY (crmid,activityid)");
  3273. //change the block for vendor address details
  3274. Execute("update vtiger_field set fieldname='street' where tabid=18 and columnname='street'");
  3275. Execute("update vtiger_field set block=46 where tabid=18 and fieldname in ('city','country','pobox','postalcode','state','street')");
  3276. //change the calendar sharing access to private
  3277. Execute("update vtiger_def_org_share set permission=3 where tabid=9");
  3278. //Now sharing access is not available for Emails
  3279. Execute("delete from vtiger_def_org_share where tabid=10");
  3280. //we have to delete the entry from datashare_relatedmodules (Settings -> Sharing Access -> Add Privileges)
  3281. Execute("delete from vtiger_datashare_relatedmodules where tabid=10");
  3282. Execute("delete from vtiger_datashare_relatedmodules where relatedto_tabid=10");
  3283. //change the share_action_name in vtiger_org_share_action_mapping table for entry Public:Read,Create/Edit
  3284. Execute('update vtiger_org_share_action_mapping set share_action_name="Public: Read, Create/Edit" where share_action_name="Public:Read,Create/Edit"');
  3285. //delete the entries from vtiger_profile2standardpermissions table for Emails
  3286. Execute("delete from vtiger_profile2standardpermissions where tabid=10");
  3287. //delete the tagcloud entry from users
  3288. Execute("delete from vtiger_field where tabid=29 and fieldname='tagcloud'");
  3289. Execute("alter table vtiger_users drop column tagcloud");
  3290. //we have missed to add the Received Shipment in postatus table
  3291. $sortorderid = $conn->query_result($conn->query("select max(sortorderid) as id from vtiger_postatus"),0,'id')+1;
  3292. Execute("insert into vtiger_postatus values('','Received Shipment',$sortorderid,1)");
  3293. Execute("alter table vtiger_attachments add index attachments_description_name_type_attachmentsid_idx (`description`,`type`,`attachmentsid`)");
  3294. //Added after 5.0 GA release
  3295. //In 4.2.3 we have assigned to group option only for Leads, HelpDesk and Activies and default None can be assigned. Now we will assign the unassigned entities to current user
  3296. Execute("update vtiger_crmentity set smownerid=1 where smownerid=0 and setype not in ('Leads','HelpDesk','Calendar')");
  3297. //CALCULATE Activity End Time (time_end)
  3298. //we have to calculate activity end time (time_end) based on start time (time_start) and duration (duration_hours, duration_minutes)
  3299. $sql = "select * from vtiger_activity";
  3300. $result = $conn->query($sql);
  3301. $num_rows = $conn->num_rows($result);
  3302. for($i=0;$i<$num_rows;$i++)
  3303. {
  3304. //First we have to retrieve the time_start, duration_hours and duration_minutes and form as a date with time
  3305. $activityid = $conn->query_result($result,$i,'activityid');
  3306. $date_start = $conn->query_result($result,$i,'date_start');
  3307. $time_start = $conn->query_result($result,$i,'time_start');
  3308. $duration_hours = $conn->query_result($result,$i,'duration_hours');
  3309. $duration_minutes = $conn->query_result($result,$i,'duration_minutes');
  3310. if($duration_hours != '' && $duration_minutes != '')
  3311. {
  3312. $date_details = explode("-",$date_start);
  3313. $start_year = $date_details[0];
  3314. $start_month = $date_details[1];
  3315. $start_date = $date_details[2];
  3316. $start_details = explode(":",$time_start);
  3317. $start_hour = $start_details[0];
  3318. $start_minutes = $start_details[1];
  3319. $full_duration = "$duration_hours:$duration_minutes:00";
  3320. $start = date("Y-m-d H:i:s",mktime($start_hour, $start_minutes, 0, $start_month, $start_date, $start_year));
  3321. $end = date("Y-m-d H:i:s",mktime($start_hour+$duration_hours, $start_minutes+$duration_minutes, 0, $start_month, $start_date, $start_year));
  3322. $end_details = explode(" ",$end);
  3323. $due_date = $end_details[0];
  3324. $end_time_details = explode(":",$end_details[1]);
  3325. $time_end = $end_time_details[0].":".$end_time_details[1];
  3326. $update_query = "update vtiger_activity set due_date=\"$due_date\", time_end=\"$time_end\" where activityid=$activityid";
  3327. $conn->query($update_query);
  3328. }
  3329. }
  3330. //Added after 5.0.1
  3331. //we have to delete the entries from customview and report related tables for deleted customfields
  3332. include("modules/Migration/deleteCustomFields.php");
  3333. //Finally add vtiger_ prefix for all the entries in 'tablename' column in field table - 2nd August 2006
  3334. $field_res = $conn->query("select fieldid, tablename from vtiger_field");
  3335. for($field_count=0;$field_count<$conn->num_rows($field_res);$field_count++)
  3336. {
  3337. //get the tablename
  3338. $tablename = $conn->query_result($field_res,$field_count,'tablename');
  3339. //check whether the table name has the prefix vtiger_
  3340. if(substr($tablename, 0, 7) != 'vtiger_')
  3341. {
  3342. $tablename = "vtiger_$tablename";
  3343. //Now update the tablename
  3344. $fieldid = $conn->query_result($field_res,$field_count,'fieldid');
  3345. Execute("update vtiger_field set tablename=\"$tablename\" where fieldid=$fieldid");
  3346. }
  3347. }
  3348. $migrationlog->debug("\n\nDB Changes from 4.2.x to 5.0 GA -------- Ends \n\n");
  3349. //Added to get the conversion rate and update for all records
  3350. ?>
  3351. <script>
  3352. function ajaxSaveResponse(response)
  3353. {
  3354. //alert(response.responseText);
  3355. alert(alert_arr.CURRENCY_CHANGE_INFO);
  3356. }
  3357. if(!confirm(alert_arr.CURRENCY_CONVERSION_INFO))
  3358. {
  3359. getConversionRate('');
  3360. }
  3361. function getConversionRate(err)
  3362. {
  3363. var crate = prompt(err+"\nPlease enter the conversion rate of your currency");
  3364. if(crate != 0 && crate > 0)
  3365. {
  3366. new Ajax.Request(
  3367. 'index.php',
  3368. {queue: {position: 'end', scope: 'command'},
  3369. method: 'post',
  3370. postBody: 'module=Migration&action=updateCurrency&ajax=1&crate='+crate,
  3371. onComplete: function(response)
  3372. {
  3373. //alert("Existing Currency values has been converted to base currency");
  3374. }
  3375. }
  3376. );
  3377. //var ajaxObj = new VtigerAjax(ajaxSaveResponse);
  3378. //url = 'module=Migration&action=updateCurrency&ajax=1&crate='+crate;
  3379. //ajaxObj.process("index.php?",url);
  3380. }
  3381. else
  3382. {
  3383. getConversionRate("Please give valid conversion rate ( > 0)");
  3384. }
  3385. }
  3386. </script>
  3387. <?php
  3388. //Function which is used to execute the query and display the result within tr tag. Also it stores the success and failure queries in a array where we can get this array to find the list of success and failure queries at the end of migraion.
  3389. function Execute($query)
  3390. {
  3391. global $conn, $query_count, $success_query_count, $failure_query_count, $success_query_array, $failure_query_array;
  3392. global $migrationlog;
  3393. $status = $conn->query($query);
  3394. $query_count++;
  3395. if(is_object($status))
  3396. {
  3397. echo '
  3398. <tr width="100%">
  3399. <td width="25%" nowrap>'.get_class($status).'</td>
  3400. <td width="5%"><font color="green"> S </font></td>
  3401. <td width="70%">'.$query.'</td>
  3402. </tr>';
  3403. $success_query_array[$success_query_count++] = $query;
  3404. $migrationlog->debug("Query Success ==> $query");
  3405. }
  3406. else
  3407. {
  3408. echo '
  3409. <tr width="100%">
  3410. <td width="25%">'.$status.'</td>
  3411. <td width="5%"><font color="red"><b> F </b></font></td>
  3412. <td width="70%">'.$query.'</td>
  3413. </tr>';
  3414. $failure_query_array[$failure_query_count++] = $query;
  3415. $migrationlog->debug("Query Failed ==> $query \n Error is ==> [".$conn->database->ErrorNo()."]".$conn->database->ErrorMsg());
  3416. //$migrationlog->debug("Error is ==> ".$conn->ErrorMsg());
  3417. }
  3418. }
  3419. //Added on 23-12-2005 which is used to populate the vtiger_profile2field and vtiger_def_org_field table entries for the field per tab
  3420. //if we enter a field in vtiger_field table then we must populate that field in these table for security access
  3421. function populateFieldForSecurity($tabid,$fieldid)
  3422. {
  3423. global $conn;
  3424. $profileresult = $conn->query("select * from vtiger_profile");
  3425. $countprofiles = $conn->num_rows($profileresult);
  3426. for ($i=0;$i<$countprofiles;$i++)
  3427. {
  3428. $profileid = $conn->query_result($profileresult,$i,'profileid');
  3429. $sqlProf2FieldInsert[$i] = 'insert into vtiger_profile2field values ('.$profileid.','.$tabid.','.$fieldid.',0,1)';
  3430. Execute($sqlProf2FieldInsert[$i]);
  3431. }
  3432. $def_query = "insert into vtiger_def_org_field values (".$tabid.",".$fieldid.",0,1)";
  3433. Execute($def_query);
  3434. }
  3435. function localcreateRole($roleName,$parentRoleId,$roleProfileArray)
  3436. {
  3437. global $migrationlog;
  3438. $migrationlog->debug("Entering localcreateRole(".$roleName.",".$parentRoleId.",".$roleProfileArray.") method ...");
  3439. global $conn;
  3440. $parentRoleDetails = localgetRoleInformation($parentRoleId);
  3441. $parentRoleInfo=$parentRoleDetails[$parentRoleId];
  3442. $roleid_no=$conn->getUniqueId("vtiger_role");
  3443. $roleId='H'.$roleid_no;
  3444. $parentRoleHr=$parentRoleInfo[1];
  3445. $parentRoleDepth=$parentRoleInfo[2];
  3446. $nowParentRoleHr=$parentRoleHr.'::'.$roleId;
  3447. $nowRoleDepth=$parentRoleDepth + 1;
  3448. //Inserting vtiger_role into db
  3449. $query="insert into vtiger_role values('".$roleId."','".$roleName."','".$nowParentRoleHr."',".$nowRoleDepth.")";
  3450. $conn->query($query);
  3451. //Inserting into vtiger_role2profile vtiger_table
  3452. foreach($roleProfileArray as $profileId)
  3453. {
  3454. if($profileId != '')
  3455. {
  3456. localinsertRole2ProfileRelation($roleId,$profileId);
  3457. }
  3458. }
  3459. $migrationlog->debug("Exiting localcreateRole method ...");
  3460. return $roleId;
  3461. }
  3462. function localgetRoleInformation($roleid)
  3463. {
  3464. global $migrationlog;
  3465. $migrationlog->debug("Entering localgetRoleInformation(".$roleid.") method ...");
  3466. global $conn;
  3467. $query = "select * from vtiger_role where roleid='".$roleid."'";
  3468. $result = $conn->query($query);
  3469. $rolename=$conn->query_result($result,0,'rolename');
  3470. $parentrole=$conn->query_result($result,0,'parentrole');
  3471. $roledepth=$conn->query_result($result,0,'depth');
  3472. $parentRoleArr=explode('::',$parentrole);
  3473. $immediateParent=$parentRoleArr[sizeof($parentRoleArr)-2];
  3474. $roleDet=Array();
  3475. $roleDet[]=$rolename;
  3476. $roleDet[]=$parentrole;
  3477. $roleDet[]=$roledepth;
  3478. $roleDet[]=$immediateParent;
  3479. $roleInfo=Array();
  3480. $roleInfo[$roleid]=$roleDet;
  3481. $migrationlog->debug("Exiting localgetRoleInformation method ...");
  3482. return $roleInfo;
  3483. }
  3484. function localinsertRole2ProfileRelation($roleId,$profileId)
  3485. {
  3486. global $migrationlog;
  3487. $migrationlog->debug("Entering localinsertRole2ProfileRelation(".$roleId.",".$profileId.") method ...");
  3488. global $conn;
  3489. $query="insert into vtiger_role2profile values('".$roleId."',".$profileId.")";
  3490. $conn->query($query);
  3491. $migrationlog->debug("Exiting localinsertRole2ProfileRelation method ...");
  3492. }
  3493. ?>