[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
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 if (!defined('VTIGER_UPGRADE')) 11 die('Invalid entry point'); 12 chdir(dirname(__FILE__) . '/../../../'); 13 include_once 'modules/com_vtiger_workflow/VTTaskManager.inc'; 14 include_once 'include/utils/utils.php'; 15 16 if(defined('VTIGER_UPGRADE')) { 17 //Collating all module package updates here 18 updateVtlibModule('Import', 'packages/vtiger/mandatory/Import.zip'); 19 updateVtlibModule('PBXManager', 'packages/vtiger/mandatory/PBXManager.zip'); 20 updateVtlibModule('MailManager', 'packages/vtiger/mandatory/MailManager.zip'); 21 updateVtlibModule('Mobile', 'packages/vtiger/mandatory/Mobile.zip'); 22 updateVtlibModule('ModTracker', 'packages/vtiger/mandatory/ModTracker.zip'); 23 updateVtlibModule('ServiceContracts', 'packages/vtiger/mandatory/ServiceContracts.zip'); 24 updateVtlibModule('Services', 'packages/vtiger/mandatory/Services.zip'); 25 updateVtlibModule('WSAPP', 'packages/vtiger/mandatory/WSAPP.zip'); 26 updateVtlibModule('Arabic_ar_ae', 'packages/vtiger/optional/Arabic_ar_ae.zip'); 27 updateVtlibModule('Assets', 'packages/vtiger/optional/Assets.zip'); 28 updateVtlibModule('EmailTemplates', 'packages/vtiger/optional/EmailTemplates.zip'); 29 updateVtlibModule('Google', 'packages/vtiger/optional/Google.zip'); 30 updateVtlibModule('ModComments', 'packages/vtiger/optional/ModComments.zip'); 31 updateVtlibModule('Projects', 'packages/vtiger/optional/Projects.zip'); 32 updateVtlibModule('RecycleBin', 'packages/vtiger/optional/RecycleBin.zip'); 33 updateVtlibModule('SMSNotifier', "packages/vtiger/optional/SMSNotifier.zip"); 34 updateVtlibModule("Sweden_sv_se","packages/vtiger/optional/Sweden_sv_se.zip"); 35 updateVtlibModule("Webforms","packages/vtiger/optional/Webforms.zip"); 36 installVtlibModule('ExtensionStore', 'packages/vtiger/marketplace/ExtensionStore.zip'); 37 } 38 if(defined('INSTALLATION_MODE')) { 39 // Set of task to be taken care while specifically in installation mode. 40 } 41 42 global $adb; 43 44 //Unlinking unwanted resources when migrating to 6.1.0 45 $unWanted=array( 46 "modules/Import/resources/Import.js", 47 "modules/Webmails/Webmails.js", 48 "modules/Webforms/Webforms.js", 49 "modules/Vendors/Vendors.js", 50 "modules/Users/Users.js", 51 "modules/Tooltip/TooltipHeaderScript.js", 52 "modules/Tooltip/Tooltip.js", 53 "modules/Tooltip/TooltipSettings.js", 54 "modules/Settings/Settings.js", 55 "modules/Services/multifile.js", 56 "modules/Services/Services.js", 57 "modules/Services/Servicesslide.js", 58 "modules/ServiceContracts/ServiceContracts.js", 59 "modules/SalesOrder/SalesOrder.js", 60 "modules/Rss/Rss.js", 61 "modules/Reports/Reports.js", 62 "modules/RecycleBin/RecycleBin.js", 63 "modules/Quotes/Quotes.js", 64 "modules/PurchaseOrder/PurchaseOrder.js", 65 "modules/ProjectTask/ProjectTask.js", 66 "modules/ProjectMilestone/ProjectMilestone.js", 67 "modules/Project/Project.js", 68 "modules/Products/Productsslide.js", 69 "modules/Products/Products.js", 70 "modules/Products/multifile.js", 71 "modules/PriceBooks/PriceBooks.js", 72 "modules/Potentials/Potentials.js", 73 "modules/Portal/Portal.js", 74 "modules/Picklist/DependencyPicklist.js", 75 "modules/PBXManager/PBXManager.js", 76 "modules/MailManager/MailManager.js", 77 "modules/Leads/Leads.js", 78 "modules/Invoice/Invoice.js", 79 "modules/Integration/Integration.js", 80 "modules/Home/Homestuff.js", 81 "modules/HelpDesk/HelpDesk.js", 82 "modules/Faq/Faq.js", 83 "modules/Emails/Emails.js", 84 "modules/Emails/GmailBookmarklet.js", 85 "modules/Emails/GmailBookmarkletTrigger.js", 86 "modules/CustomerPortal/CustomerPortal.js", 87 "modules/CronTasks/CronTasks.js", 88 "modules/Contacts/Contacts.js", 89 "modules/ConfigurationEditor/ConfigEditor.js", 90 "modules/Documents/Documents.js", 91 "modules/CustomView/CustomView.js", 92 "modules/ModComments/ModComments.js", 93 "modules/ModComments/ModCommentsCommon.js", 94 "modules/ModTracker/ModTracker.js", 95 "modules/ModTracker/ModTrackerCommon.js", 96 "modules/com_vtiger_workflow/resources/functional.js", 97 "modules/com_vtiger_workflow/resources/parallelexecuter.js", 98 "modules/com_vtiger_workflow/resources/editworkflowscript.js", 99 "modules/com_vtiger_workflow/resources/createtodotaskscript.js", 100 "modules/com_vtiger_workflow/resources/fieldexpressionpopup.js", 101 "modules/com_vtiger_workflow/resources/workflowlistscript.js", 102 "modules/com_vtiger_workflow/resources/fieldvalidator.js", 103 "modules/com_vtiger_workflow/resources/updatefieldstaskscript.js", 104 "modules/com_vtiger_workflow/resources/jquery-1.2.6.js", 105 "modules/com_vtiger_workflow/resources/json2.js", 106 "modules/com_vtiger_workflow/resources/vtigerwebservices.js", 107 "modules/com_vtiger_workflow/resources/jquery.timepicker.js", 108 "modules/com_vtiger_workflow/resources/createentitytaskscript.js", 109 "modules/com_vtiger_workflow/resources/edittaskscript.js", 110 "modules/com_vtiger_workflow/resources/createeventtaskscript.js", 111 "modules/com_vtiger_workflow/resources/emailtaskscript.js", 112 "modules/FieldFormulas/editexpressionscript.js", 113 "modules/FieldFormulas/jquery-1.2.6.js", 114 "modules/FieldFormulas/json2.js", 115 "modules/FieldFormulas/vtigerwebservices.js", 116 "modules/FieldFormulas/functional.js" 117 ); 118 119 for($i=0;$i<=count($unWanted);$i++){ 120 if(file_exists($unWanted[$i])){ 121 unlink($unWanted[$i]); 122 } 123 } 124 125 $result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('schtypeid')); 126 if (!($adb->num_rows($result))) { 127 $adb->pquery("ALTER TABLE com_vtiger_workflows ADD schtypeid INT(10)", array()); 128 } 129 $result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('schtime')); 130 if (!($adb->num_rows($result))) { 131 $adb->pquery("ALTER TABLE com_vtiger_workflows ADD schtime TIME", array()); 132 } 133 $result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('schdayofmonth')); 134 if (!($adb->num_rows($result))) { 135 $adb->pquery("ALTER TABLE com_vtiger_workflows ADD schdayofmonth VARCHAR(100)", array()); 136 } 137 $result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('schdayofweek')); 138 if (!($adb->num_rows($result))) { 139 $adb->pquery("ALTER TABLE com_vtiger_workflows ADD schdayofweek VARCHAR(100)", array()); 140 } 141 $result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('schannualdates')); 142 if (!($adb->num_rows($result))) { 143 $adb->pquery("ALTER TABLE com_vtiger_workflows ADD schannualdates VARCHAR(100)", array()); 144 } 145 $result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('nexttrigger_time')); 146 if (!($adb->num_rows($result))) { 147 $adb->pquery("ALTER TABLE com_vtiger_workflows ADD nexttrigger_time DATETIME", array()); 148 } 149 150 Migration_Index_View::ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_faqcf ( 151 faqid int(19), 152 PRIMARY KEY (faqid), 153 CONSTRAINT fk_1_vtiger_faqcf FOREIGN KEY (faqid) REFERENCES vtiger_faq(id) ON DELETE CASCADE 154 ) ENGINE=InnoDB DEFAULT CHARSET=utf8", array()); 155 156 echo "FAQ cf created"; 157 158 //73 starts 159 $query = 'SELECT 1 FROM vtiger_currencies WHERE currency_name=?'; 160 $result = $adb->pquery($query, array('Sudanese Pound')); 161 if($adb->num_rows($result) <= 0){ 162 //Inserting Currency Sudanese Pound to vtiger_currencies 163 Migration_Index_View::ExecuteQuery('INSERT INTO vtiger_currencies (currencyid,currency_name,currency_code,currency_symbol) VALUES ('.$adb->getUniqueID("vtiger_currencies").',"Sudanese Pound","SDG","£")',array()); 164 Vtiger_Utils::AddColumn('vtiger_mailmanager_mailattachments', 'cid', 'VARCHAR(100)'); 165 } 166 //73 ends 167 168 //74 starts 169 170 //Start: Moving Entity methods of Tickets to Workflows 171 $result = $adb->pquery('SELECT DISTINCT workflow_id FROM com_vtiger_workflowtasks WHERE workflow_id IN 172 (SELECT workflow_id FROM com_vtiger_workflows WHERE module_name IN (?) AND defaultworkflow = ?) 173 AND task LIKE ?', array($moduleName, 1, '%VTEntityMethodTask%')); 174 $numOfRows = $adb->num_rows($result); 175 176 for($i=0; $i<$numOfRows; $i++) { 177 $wfs = new VTWorkflowManager($adb); 178 $workflowModel = $wfs->retrieve($adb->query_result($result, $i, 'workflow_id')); 179 $workflowModel->filtersavedinnew = 6; 180 181 $tm = new VTTaskManager($adb); 182 $tasks = $tm->getTasksForWorkflow($workflowModel->id); 183 foreach ($tasks as $task) { 184 $properties = get_object_vars($task); 185 186 $emailTask = new VTEmailTask(); 187 $emailTask->executeImmediately = 0; 188 $emailTask->summary = $properties['summary']; 189 $emailTask->active = $properties['active']; 190 switch($properties['methodName']) { 191 case 'NotifyOnPortalTicketCreation' : 192 $conditions = Zend_Json::decode($workflowModel->test); 193 $oldCondtions = array(); 194 195 if(!empty($conditions)) { 196 $previousConditionGroupId = 0; 197 foreach($conditions as $condition) { 198 199 $fieldName = $condition['fieldname']; 200 $fieldNameContents = explode(' ', $fieldName); 201 if (count($fieldNameContents) > 1) { 202 $fieldName = '('. $fieldName .')'; 203 } 204 205 $groupId = $condition['groupid']; 206 if (!$groupId) { 207 $groupId = 0; 208 } 209 210 $groupCondition = 'or'; 211 if ($groupId === $previousConditionGroupId || count($conditions) === 1) { 212 $groupCondition = 'and'; 213 } 214 215 $joinCondition = 'or'; 216 if (isset ($condition['joincondition'])) { 217 $joinCondition = $condition['joincondition']; 218 } elseif($groupId === 0) { 219 $joinCondition = 'and'; 220 } 221 222 $value = $condition['value']; 223 switch ($value) { 224 case 'false:boolean' : $value = 0; break; 225 case 'true:boolean' : $value = 1; break; 226 default : $value; break; 227 } 228 229 $oldCondtions[] = array( 230 'fieldname' => $fieldName, 231 'operation' => $condition['operation'], 232 'value' => $value, 233 'valuetype' => 'rawtext', 234 'joincondition' => $joinCondition, 235 'groupjoin' => $groupCondition, 236 'groupid' => $groupId 237 ); 238 $previousConditionGroupId = $groupId; 239 } 240 } 241 $newConditions = array( 242 array('fieldname' => 'from_portal', 243 'operation' => 'is', 244 'value' => '1', 245 'valuetype' => 'rawtext', 246 'joincondition' => '', 247 'groupjoin' => 'and', 248 'groupid' => '0') 249 ); 250 $newConditions = array_merge($oldCondtions, $newConditions); 251 252 $workflowModel->test = Zend_Json::encode($newConditions); 253 $workflowModel->description = 'Ticket Creation From Portal : Send Email to Record Owner and Contact'; 254 $wfs->save($workflowModel); 255 256 $emailTask->id = ''; 257 $emailTask->workflowId = $properties['workflowId']; 258 $emailTask->summary = 'Notify Record Owner when Ticket is created from Portal'; 259 $emailTask->fromEmail = '$(contact_id : (Contacts) lastname) $(contact_id : (Contacts) firstname)<$(general : (__VtigerMeta__) supportEmailId)>'; 260 $emailTask->recepient = ',$(assigned_user_id : (Users) email1)'; 261 $emailTask->subject = '[From Portal] $ticket_no [ Ticket Id : $(general : (__VtigerMeta__) recordId) ] $ticket_title'; 262 $emailTask->content = 'Ticket No : $ticket_no<br> 263 Ticket ID : $(general : (__VtigerMeta__) recordId)<br> 264 Ticket Title : $ticket_title<br><br> 265 $description'; 266 $tm->saveTask($emailTask); 267 268 $emailTask->id = $properties['id']; 269 $emailTask->summary = 'Notify Related Contact when Ticket is created from Portal'; 270 $emailTask->fromEmail = '$(general : (__VtigerMeta__) supportName)<$(general : (__VtigerMeta__) supportEmailId)>'; 271 $emailTask->recepient = ',$(contact_id : (Contacts) email)'; 272 273 $tm->saveTask($emailTask); 274 break; 275 case 'NotifyOnPortalTicketComment' : 276 $tm->deleteTask($properties['id']); 277 Migration_Index_View::ExecuteQuery('DELETE FROM com_vtiger_workflows WHERE workflow_id = ?', array($workflowModel->id)); 278 break; 279 280 case 'NotifyParentOnTicketChange' : 281 $newWorkflowModel = $wfs->newWorkflow($workflowModel->moduleName); 282 $workflowProperties = get_object_vars($workflowModel); 283 foreach ($workflowProperties as $workflowPropertyName => $workflowPropertyValue) { 284 $newWorkflowModel->$workflowPropertyName = $workflowPropertyValue; 285 } 286 287 $conditions = Zend_Json::decode($newWorkflowModel->test); 288 $oldCondtions = array(); 289 290 if(!empty($conditions)) { 291 $previousConditionGroupId = 0; 292 foreach($conditions as $condition) { 293 294 $fieldName = $condition['fieldname']; 295 $fieldNameContents = explode(' ', $fieldName); 296 if (count($fieldNameContents) > 1) { 297 $fieldName = '('. $fieldName .')'; 298 } 299 300 $groupId = $condition['groupid']; 301 if (!$groupId) { 302 $groupId = 0; 303 } 304 305 $groupCondition = 'or'; 306 if ($groupId === $previousConditionGroupId || count($conditions) === 1) { 307 $groupCondition = 'and'; 308 } 309 310 $joinCondition = 'or'; 311 if (isset ($condition['joincondition'])) { 312 $joinCondition = $condition['joincondition']; 313 } elseif($groupId === 0) { 314 $joinCondition = 'and'; 315 } 316 317 $value = $condition['value']; 318 switch ($value) { 319 case 'false:boolean' : $value = 0; break; 320 case 'true:boolean' : $value = 1; break; 321 default : $value; break; 322 } 323 324 $oldCondtions[] = array( 325 'fieldname' => $fieldName, 326 'operation' => $condition['operation'], 327 'value' => $value, 328 'valuetype' => 'rawtext', 329 'joincondition' => $joinCondition, 330 'groupjoin' => $groupCondition, 331 'groupid' => $groupId 332 ); 333 $previousConditionGroupId = $groupId; 334 } 335 } 336 $newConditions = array( 337 array('fieldname' => 'ticketstatus', 338 'operation' => 'has changed to', 339 'value' => 'Closed', 340 'valuetype' => 'rawtext', 341 'joincondition' => 'or', 342 'groupjoin' => 'and', 343 'groupid' => '1'), 344 array('fieldname' => 'solution', 345 'operation' => 'has changed', 346 'value' => '', 347 'valuetype' => '', 348 'joincondition' => 'or', 349 'groupjoin' => 'and', 350 'groupid' => '1'), 351 array('fieldname' => 'description', 352 'operation' => 'has changed', 353 'value' => '', 354 'valuetype' => '', 355 'joincondition' => 'or', 356 'groupjoin' => 'and', 357 'groupid' => '1') 358 ); 359 $newConditions = array_merge($oldCondtions, $newConditions); 360 361 $newAccountCondition = array( 362 array('fieldname' => '(parent_id : (Accounts) emailoptout)', 363 'operation' => 'is', 364 'value' => '0', 365 'valuetype' => 'rawtext', 366 'joincondition' => 'and', 367 'groupjoin' => 'and', 368 'groupid' => '0') 369 ); 370 $newWorkflowConditions = array_merge($newAccountCondition, $newConditions); 371 372 unset($newWorkflowModel->id); 373 $newWorkflowModel->test = Zend_Json::encode($newWorkflowConditions); 374 $newWorkflowModel->description = 'Send Email to Organization on Ticket Update'; 375 $wfs->save($newWorkflowModel); 376 377 $emailTask->id = ''; 378 $emailTask->summary = 'Send Email to Organization on Ticket Update'; 379 $emailTask->fromEmail = '$(general : (__VtigerMeta__) supportName)<$(general : (__VtigerMeta__) supportEmailId)>'; 380 $emailTask->recepient = ',$(parent_id : (Accounts) email1)'; 381 $emailTask->subject = '$ticket_no [ Ticket Id : $(general : (__VtigerMeta__) recordId) ] $ticket_title'; 382 $emailTask->content = 'Ticket ID : $(general : (__VtigerMeta__) recordId)<br>Ticket Title : $ticket_title<br><br> 383 Dear $(parent_id : (Accounts) accountname),<br><br> 384 The Ticket is replied the details are :<br><br> 385 Ticket No : $ticket_no<br> 386 Status : $ticketstatus<br> 387 Category : $ticketcategories<br> 388 Severity : $ticketseverities<br> 389 Priority : $ticketpriorities<br><br> 390 Description : <br>$description<br><br> 391 Solution : <br>$solution<br> 392 The comments are : <br> 393 $allComments<br><br> 394 Regards<br>Support Administrator'; 395 396 $emailTask->workflowId = $newWorkflowModel->id; 397 $tm->saveTask($emailTask); 398 399 $portalCondition = array( 400 array('fieldname' => 'from_portal', 401 'operation' => 'is', 402 'value' => '0', 403 'valuetype' => 'rawtext', 404 'joincondition' => '', 405 'groupjoin' => 'and', 406 'groupid' => '0') 407 ); 408 409 unset($newWorkflowModel->id); 410 $newWorkflowModel->executionCondition = 1; 411 $newWorkflowModel->test = Zend_Json::encode(array_merge($newAccountCondition, $portalCondition)); 412 $newWorkflowModel->description = 'Ticket Creation From CRM : Send Email to Organization'; 413 $wfs->save($newWorkflowModel); 414 415 $emailTask->id = ''; 416 $emailTask->workflowId = $newWorkflowModel->id; 417 $emailTask->summary = 'Ticket Creation From CRM : Send Email to Organization'; 418 $tm->saveTask($emailTask); 419 420 $newContactCondition = array( 421 array('fieldname' => '(contact_id : (Contacts) emailoptout)', 422 'operation' => 'is', 423 'value' => '0', 424 'valuetype' => 'rawtext', 425 'joincondition' => 'and', 426 'groupjoin' => 'and', 427 'groupid' => '0') 428 ); 429 $newConditions = array_merge($newContactCondition, $newConditions); 430 431 $workflowModel->test = Zend_Json::encode($newConditions); 432 $workflowModel->description = 'Send Email to Contact on Ticket Update'; 433 $wfs->save($workflowModel); 434 435 $emailTask->id = $properties['id']; 436 $emailTask->workflowId = $properties['workflowId']; 437 $emailTask->summary = 'Send Email to Contact on Ticket Update'; 438 $emailTask->recepient = ',$(contact_id : (Contacts) email)'; 439 $emailTask->content = 'Ticket ID : $(general : (__VtigerMeta__) recordId)<br>Ticket Title : $ticket_title<br><br> 440 Dear $(contact_id : (Contacts) lastname) $(contact_id : (Contacts) firstname),<br><br> 441 The Ticket is replied the details are :<br><br> 442 Ticket No : $ticket_no<br> 443 Status : $ticketstatus<br> 444 Category : $ticketcategories<br> 445 Severity : $ticketseverities<br> 446 Priority : $ticketpriorities<br><br> 447 Description : <br>$description<br><br> 448 Solution : <br>$solution<br> 449 The comments are : <br> 450 $allComments<br><br> 451 Regards<br>Support Administrator'; 452 453 $tm->saveTask($emailTask); 454 455 unset($newWorkflowModel->id); 456 $newWorkflowModel->executionCondition = 1; 457 $newWorkflowModel->test = Zend_Json::encode(array_merge($newContactCondition, $portalCondition)); 458 $newWorkflowModel->description = 'Ticket Creation From CRM : Send Email to Contact'; 459 $wfs->save($newWorkflowModel); 460 461 $emailTask->id = ''; 462 $emailTask->workflowId = $newWorkflowModel->id; 463 $emailTask->summary = 'Ticket Creation From CRM : Send Email to Contact'; 464 $tm->saveTask($emailTask); 465 break; 466 467 468 case 'NotifyOwnerOnTicketChange' : 469 $tm->deleteTask($task->id); 470 471 $newWorkflowModel = $wfs->newWorkflow($workflowModel->moduleName); 472 $workflowProperties = get_object_vars($workflowModel); 473 foreach ($workflowProperties as $workflowPropertyName => $workflowPropertyValue) { 474 $newWorkflowModel->$workflowPropertyName = $workflowPropertyValue; 475 } 476 477 $conditions = Zend_Json::decode($newWorkflowModel->test); 478 $oldCondtions = array(); 479 480 if(!empty($conditions)) { 481 $previousConditionGroupId = 0; 482 foreach($conditions as $condition) { 483 484 $fieldName = $condition['fieldname']; 485 $fieldNameContents = explode(' ', $fieldName); 486 if (count($fieldNameContents) > 1) { 487 $fieldName = '('. $fieldName .')'; 488 } 489 490 $groupId = $condition['groupid']; 491 if (!$groupId) { 492 $groupId = 0; 493 } 494 495 $groupCondition = 'or'; 496 if ($groupId === $previousConditionGroupId || count($conditions) === 1) { 497 $groupCondition = 'and'; 498 } 499 500 $joinCondition = 'or'; 501 if (isset ($condition['joincondition'])) { 502 $joinCondition = $condition['joincondition']; 503 } elseif($groupId === 0) { 504 $joinCondition = 'and'; 505 } 506 507 $value = $condition['value']; 508 switch ($value) { 509 case 'false:boolean' : $value = 0; break; 510 case 'true:boolean' : $value = 1; break; 511 default : $value; break; 512 } 513 514 $oldCondtions[] = array( 515 'fieldname' => $fieldName, 516 'operation' => $condition['operation'], 517 'value' => $value, 518 'valuetype' => 'rawtext', 519 'joincondition' => $joinCondition, 520 'groupjoin' => $groupCondition, 521 'groupid' => $groupId 522 ); 523 $previousConditionGroupId = $groupId; 524 } 525 } 526 $newConditions = array( 527 array('fieldname' => 'ticketstatus', 528 'operation' => 'has changed to', 529 'value' => 'Closed', 530 'valuetype' => 'rawtext', 531 'joincondition' => 'or', 532 'groupjoin' => 'and', 533 'groupid' => '1'), 534 array('fieldname' => 'solution', 535 'operation' => 'has changed', 536 'value' => '', 537 'valuetype' => '', 538 'joincondition' => 'or', 539 'groupjoin' => 'and', 540 'groupid' => '1'), 541 array('fieldname' => 'assigned_user_id', 542 'operation' => 'has changed', 543 'value' => '', 544 'valuetype' => '', 545 'joincondition' => 'or', 546 'groupjoin' => 'and', 547 'groupid' => '1'), 548 array('fieldname' => 'description', 549 'operation' => 'has changed', 550 'value' => '', 551 'valuetype' => '', 552 'joincondition' => 'or', 553 'groupjoin' => 'and', 554 'groupid' => '1') 555 556 ); 557 $newConditions = array_merge($oldCondtions, $newConditions); 558 559 unset($newWorkflowModel->id); 560 $newWorkflowModel->test = Zend_Json::encode($newConditions); 561 $newWorkflowModel->description = 'Send Email to Record Owner on Ticket Update'; 562 $wfs->save($newWorkflowModel); 563 564 $emailTask->id = ''; 565 $emailTask->workflowId = $newWorkflowModel->id; 566 $emailTask->summary = 'Send Email to Record Owner on Ticket Update'; 567 $emailTask->fromEmail = '$(general : (__VtigerMeta__) supportName)<$(general : (__VtigerMeta__) supportEmailId)>'; 568 $emailTask->recepient = ',$(assigned_user_id : (Users) email1)'; 569 $emailTask->subject = 'Ticket Number : $ticket_no $ticket_title'; 570 $emailTask->content = 'Ticket ID : $(general : (__VtigerMeta__) recordId)<br>Ticket Title : $ticket_title<br><br> 571 Dear $(assigned_user_id : (Users) last_name) $(assigned_user_id : (Users) first_name),<br><br> 572 The Ticket is replied the details are :<br><br> 573 Ticket No : $ticket_no<br> 574 Status : $ticketstatus<br> 575 Category : $ticketcategories<br> 576 Severity : $ticketseverities<br> 577 Priority : $ticketpriorities<br><br> 578 Description : <br>$description<br><br> 579 Solution : <br>$solution 580 $allComments<br><br> 581 Regards<br>Support Administrator'; 582 $emailTask->id = ''; 583 $tm->saveTask($emailTask); 584 585 $portalCondition = array( 586 array('fieldname' => 'from_portal', 587 'operation' => 'is', 588 'value' => '0', 589 'valuetype' => 'rawtext', 590 'joincondition' => '', 591 'groupjoin' => 'and', 592 'groupid' => '0') 593 ); 594 595 unset($newWorkflowModel->id); 596 $newWorkflowModel->executionCondition = 1; 597 $newWorkflowModel->test = Zend_Json::encode($portalCondition); 598 $newWorkflowModel->description = 'Ticket Creation From CRM : Send Email to Record Owner'; 599 $wfs->save($newWorkflowModel); 600 601 $emailTask->id = ''; 602 $emailTask->workflowId = $newWorkflowModel->id; 603 $emailTask->summary = 'Ticket Creation From CRM : Send Email to Record Owner'; 604 $tm->saveTask($emailTask); 605 break; 606 } 607 } 608 } 609 echo '<br>SuccessFully Done For Tickets<br>'; 610 //End: Moved Entity methods of Tickets to Workflows 611 //74 ends 612 613 //75 starts 614 //create new table for feedback on removing old version 615 $adb->query("CREATE TABLE IF NOT EXISTS vtiger_feedback (userid INT(19), dontshow VARCHAR(19) default false);"); 616 617 //75 ends 618 619 //76 starts 620 $moduleInstance = Vtiger_Module::getInstance('Calendar'); 621 $fieldInstance = Vtiger_Field::getInstance('activitytype',$moduleInstance); 622 623 $fieldInstance->setPicklistValues(array('Mobile Call')); 624 //76 ends 625 626 //77 starts 627 $sql = "ALTER TABLE vtiger_products MODIFY productname VARCHAR( 100 )"; 628 Migration_Index_View::ExecuteQuery($sql,array()); 629 echo "<br>Updated to varchar(100) for productname"; 630 631 $result = $adb->pquery('SELECT 1 FROM vtiger_currencies WHERE currency_name = ?', array('CFA Franc BCEAO')); 632 if(!$adb->num_rows($result)) { 633 Migration_Index_View::ExecuteQuery('INSERT INTO vtiger_currencies (currencyid, currency_name, currency_code, currency_symbol) VALUES(?, ?, ?, ?)', 634 array($adb->getUniqueID('vtiger_currencies'), 'CFA Franc BCEAO', 'XOF', 'CFA')); 635 } 636 $result = $adb->pquery('SELECT 1 FROM vtiger_currencies WHERE currency_name = ?', array('CFA Franc BEAC')); 637 if(!$adb->num_rows($result)) { 638 Migration_Index_View::ExecuteQuery('INSERT INTO vtiger_currencies (currencyid, currency_name, currency_code, currency_symbol) VALUES(?, ?, ?, ?)', 639 array($adb->getUniqueID('vtiger_currencies'), 'CFA Franc BEAC', 'XAF', 'CFA')); 640 } 641 echo "<br>Added CFA Franc BCEAO and CFA Franc BEAC currencies"; 642 643 $sql = "ALTER TABLE vtiger_loginhistory MODIFY user_name VARCHAR( 255 )"; 644 Migration_Index_View::ExecuteQuery($sql,array()); 645 646 $sql = "UPDATE vtiger_activitytype SET presence = '0' WHERE activitytype ='Mobile Call'"; 647 Migration_Index_View::ExecuteQuery($sql,array()); 648 //77 ends(Some function addGroupTaxTemplatesForQuotesAndPurchaseOrder) 649 650 //78 starts 651 //78 ends 652 653 //79 starts 654 Migration_Index_View::ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_shareduserinfo 655 (userid INT(19) NOT NULL default 0, shareduserid INT(19) NOT NULL default 0, 656 color VARCHAR(50), visible INT(19) default 1);", array()); 657 658 Migration_Index_View::ExecuteQuery('ALTER TABLE vtiger_mailscanner_rules ADD assigned_to INT(10), ADD cc VARCHAR(255), ADD bcc VARCHAR(255)', array()); 659 $assignedToId = Users::getActiveAdminId(); 660 Migration_Index_View::ExecuteQuery("UPDATE vtiger_mailscanner_rules SET assigned_to=?", array($assignedToId)); 661 echo "<br> Adding assigned to, cc, bcc fields for mail scanner rules"; 662 663 664 //Schema changes for vtiger_troubletickets hours & days column 665 Migration_Index_View::ExecuteQuery('ALTER TABLE vtiger_troubletickets MODIFY hours decimal(25,8)', array()); 666 Migration_Index_View::ExecuteQuery('ALTER TABLE vtiger_troubletickets MODIFY days decimal(25,8)', array()); 667 668 Migration_Index_View::ExecuteQuery("UPDATE vtiger_field SET defaultvalue=? WHERE tablename=? and fieldname=?", array('1', 'vtiger_pricebook', 'active')); 669 echo "<br> updated default value for pricebooks active"; 670 671 $relationId = $adb->getUniqueID('vtiger_relatedlists'); 672 $contactTabId = getTabid('Contacts'); 673 $vendorTabId = getTabId('Vendors'); 674 $actions = 'SELECT'; 675 676 $query = 'SELECT max(sequence) as maxsequence FROM vtiger_relatedlists where tabid = ?'; 677 $result = $adb->pquery($query, array($contactTabId)); 678 $sequence = $adb->query_result($result, 0 ,'maxsequence'); 679 680 $query = 'INSERT INTO vtiger_relatedlists VALUES(?,?,?,?,?,?,?,?)'; 681 $result = Migration_Index_View::ExecuteQuery($query, array($relationId, $contactTabId,$vendorTabId,'get_vendors',($sequence+1),'Vendors',0,$actions)); 682 683 //Schema changes for vtiger_troubletickets hours & days column 684 Migration_Index_View::ExecuteQuery('UPDATE vtiger_field set typeofdata=? WHERE fieldname IN(?,?) AND tablename = ?', array('N~O', 'hours', 'days', 'vtiger_troubletickets')); 685 686 //79 ends 687 688 //80 starts 689 //Added recurring enddate column for events,to vtiger_recurringevents table 690 Migration_Index_View::ExecuteQuery('ALTER TABLE vtiger_recurringevents ADD COLUMN recurringenddate date', array()); 691 echo "added field recurring enddate to vtiger_recurringevents to save untill date of repeat events"; 692 693 //80 ends 694 695 //81 starts 696 //81 ends 697 698 //82 starts 699 Migration_Index_View::ExecuteQuery("ALTER TABLE vtiger_mailscanner CHANGE timezone time_zone VARCHAR(10)", array()); 700 echo "<br>Changed timezone column name for mail scanner"; 701 702 //82 ends 703 704 //83 starts 705 $result = $adb->pquery('SELECT task_id FROM com_vtiger_workflowtasks WHERE workflow_id IN 706 (SELECT workflow_id FROM com_vtiger_workflows WHERE module_name IN (?, ?)) 707 AND task LIKE ?', array('Calendar', 'Events', '%VTSendNotificationTask%')); 708 $numOfRowas = $adb->num_rows($result); 709 for ($i = 0; $i < $numOfRows; $i++) { 710 $tm = new VTTaskManager($adb); 711 $task = $tm->retrieveTask($adb->query_result($result, $i, 'task_id')); 712 713 $emailTask = new VTEmailTask(); 714 $properties = get_object_vars($task); 715 foreach ($properties as $propertyName => $propertyValue) { 716 $propertyValue = str_replace('$date_start $time_start ( $(general : (__VtigerMeta__) usertimezone) ) ', '$date_start', $propertyValue); 717 $propertyValue = str_replace('$due_date $time_end ( $(general : (__VtigerMeta__) usertimezone) )', '$due_date', $propertyValue); 718 $propertyValue = str_replace('$due_date ( $(general : (__VtigerMeta__) usertimezone) )', '$due_date', $propertyValue); 719 $propertyValue = str_replace('$(contact_id : (Contacts) lastname) $(contact_id : (Contacts) firstname)', '$contact_id', $propertyValue); 720 $emailTask->$propertyName = $propertyValue; 721 } 722 723 $tm->saveTask($emailTask); 724 } 725 echo '<br>Successfully Done<br>'; 726 727 //83 ends 728 729 //84 starts 730 $query = "ALTER table vtiger_relcriteria modify comparator varchar(20)"; 731 Migration_Index_View::ExecuteQuery($query, array()); 732 733 //To copy imagename saved in vtiger_attachments for products and contacts into respectively base table 734 //to support filters on imagename field 735 $productIdSql = 'SELECT productid,name FROM vtiger_seattachmentsrel INNER JOIN vtiger_attachments ON 736 vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid INNER JOIN vtiger_products ON 737 vtiger_products.productid = vtiger_seattachmentsrel.crmid'; 738 $productIds = $adb->pquery($productIdSql,array()); 739 $numOfRows = $adb->num_rows($productIds); 740 741 $productImageMap = array(); 742 for ($i = 0; $i < $numOfRows; $i++) { 743 $productId = $adb->query_result($productIds, $i, "productid"); 744 $imageName = decode_html($adb->query_result($productIds, $i, "name")); 745 if(!empty($productImageMap[$productId])){ 746 array_push($productImageMap[$productId], $imageName); 747 }elseif(empty($productImageMap[$productId])){ 748 $productImageMap[$productId] = array($imageName); 749 } 750 } 751 foreach ($productImageMap as $productId => $imageNames) { 752 $implodedNames = implode(",", $imageNames); 753 Migration_Index_View::ExecuteQuery('UPDATE vtiger_products SET imagename = ? WHERE productid = ?',array($implodedNames,$productId)); 754 } 755 echo 'updating image information for products table is completed'; 756 757 $ContactIdSql = 'SELECT contactid,name FROM vtiger_seattachmentsrel INNER JOIN vtiger_attachments ON 758 vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid INNER JOIN vtiger_contactdetails ON 759 vtiger_contactdetails.contactid = vtiger_seattachmentsrel.crmid'; 760 $contactIds = $adb->pquery($ContactIdSql,array()); 761 $numOfRows = $adb->num_rows($contactIds); 762 763 for ($i = 0; $i < $numOfRows; $i++) { 764 $contactId = $adb->query_result($contactIds, $i, "contactid"); 765 $imageName = decode_html($adb->query_result($contactIds, $i, "name")); 766 Migration_Index_View::ExecuteQuery('UPDATE vtiger_contactdetails SET imagename = ? WHERE contactid = ?',array($imageName,$contactId)); 767 } 768 echo 'updating image information for contacts table is completed'; 769 770 //Updating actions for PriceBooks related list in Products and Services 771 $productsTabId = getTabId('Products'); 772 773 Migration_Index_View::ExecuteQuery("UPDATE vtiger_relatedlists SET actions=? WHERE label=? and tabid=? ",array('ADD,SELECT', 'PriceBooks', $productsTabId)); 774 echo '<br>Updated PriceBooks related list actions for products and services'; 775 776 $adb->pquery("CREATE TABLE IF NOT EXISTS vtiger_schedulereports( 777 reportid INT(10), 778 scheduleid INT(3), 779 recipients TEXT, 780 schdate VARCHAR(20), 781 schtime TIME, 782 schdayoftheweek VARCHAR(100), 783 schdayofthemonth VARCHAR(100), 784 schannualdates VARCHAR(500), 785 specificemails VARCHAR(500), 786 next_trigger_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP) 787 ENGINE=InnoDB DEFAULT CHARSET=utf8;", array()); 788 789 Vtiger_Cron::register('ScheduleReports', 'cron/modules/Reports/ScheduleReports.service', 900); 790 791 Migration_Index_View::ExecuteQuery('UPDATE vtiger_cron_task set description = ? where name = "ScheduleReports" ', array("Recommended frequency for ScheduleReports is 15 mins")); 792 Migration_Index_View::ExecuteQuery('UPDATE vtiger_cron_task set module = ? where name = "ScheduleReports" ', array("Reports")); 793 echo '<br>Enabled Scheduled reports feature'; 794 795 /** 796 * To add defaulteventstatus and defaultactivitytype fields to Users Module 797 * Save 2 clicks usability feature 798 */ 799 require_once 'vtlib/Vtiger/Module.php'; 800 $module = Vtiger_Module::getInstance('Users'); 801 if ($module) { 802 $blockInstance = Vtiger_Block::getInstance('LBL_CALENDAR_SETTINGS', $module); 803 if ($blockInstance) { 804 $desField = Vtiger_Field::getInstance('defaulteventstatus', $module); 805 if(!$desField) { 806 $fieldInstance = new Vtiger_Field(); 807 $fieldInstance->name = 'defaulteventstatus'; 808 $fieldInstance->label = 'Default Event Status'; 809 $fieldInstance->uitype = 15; 810 $fieldInstance->column = $fieldInstance->name; 811 $fieldInstance->columntype = 'VARCHAR(50)'; 812 $fieldInstance->typeofdata = 'V~O'; 813 $blockInstance->addField($fieldInstance); 814 $fieldInstance->setPicklistValues(Array('Planned','Held','Not Held')); 815 } 816 $datField = Vtiger_Field::getInstance('defaultactivitytype', $module); 817 if(!$datField) { 818 $fieldInstance1 = new Vtiger_Field(); 819 $fieldInstance1->name = 'defaultactivitytype'; 820 $fieldInstance1->label = 'Default Activity Type'; 821 $fieldInstance1->uitype = 15; 822 $fieldInstance1->column = $fieldInstance1->name; 823 $fieldInstance1->columntype = 'VARCHAR(50)'; 824 $fieldInstance1->typeofdata = 'V~O'; 825 $blockInstance->addField($fieldInstance1); 826 $fieldInstance1->setPicklistValues(Array('Call','Meeting')); 827 } 828 } 829 } 830 echo 'Default status and activitytype field created'; 831 //84 ends 832 833 //85 starts 834 Migration_Index_View::ExecuteQuery('ALTER TABLE vtiger_account ALTER isconvertedfromlead SET DEFAULT ?', array('0')); 835 Migration_Index_View::ExecuteQuery('ALTER TABLE vtiger_contactdetails ALTER isconvertedfromlead SET DEFAULT ?', array('0')); 836 Migration_Index_View::ExecuteQuery('ALTER TABLE vtiger_potential ALTER isconvertedfromlead SET DEFAULT ?', array('0')); 837 Migration_Index_View::ExecuteQuery('Update vtiger_account SET isconvertedfromlead = ? where isconvertedfromlead is NULL',array('0')); 838 Migration_Index_View::ExecuteQuery('Update vtiger_contactdetails SET isconvertedfromlead = ? where isconvertedfromlead is NULL',array('0')); 839 Migration_Index_View::ExecuteQuery('Update vtiger_potential SET isconvertedfromlead = ? where isconvertedfromlead is NULL',array('0')); 840 841 //85 ends 842 843 //86 starts 844 //Duplicate of 85 script 845 //86 ends 846 847 //87 starts 848 $result = $adb->pquery('SELECT 1 FROM vtiger_currencies WHERE currency_name = ?', array('Haiti, Gourde')); 849 if(!$adb->num_rows($result)) { 850 Migration_Index_View::ExecuteQuery('INSERT INTO vtiger_currencies (currencyid, currency_name, currency_code, currency_symbol) VALUES(?, ?, ?, ?)', 851 array($adb->getUniqueID('vtiger_currencies'), 'Haiti, Gourde', 'HTG', 'G')); 852 } 853 //87 ends 854 855 //88 starts 856 Migration_Index_View::ExecuteQuery("UPDATE vtiger_currencies SET currency_symbol=? WHERE currency_code=?", array('₹','INR')); 857 Migration_Index_View::ExecuteQuery("UPDATE vtiger_currency_info SET currency_symbol=? WHERE currency_code=?", array('₹','INR')); 858 859 Migration_Index_View::ExecuteQuery('UPDATE vtiger_projecttaskstatus set presence = 0 where projecttaskstatus in (?,?,?,?,?)', 860 array('Open','In Progress','Completed','Deferred','Canceled')); 861 echo '<br> made projecttaskstatus picklist values as non editable'; 862 863 //88 ends 864 865 //89 starts 866 //89 ends 867 868 //90 starts 869 //Updating User fields Sequence 870 $userFields = array('user_name', 'email1', 'first_name', 'last_name', 'user_password', 'confirm_password', 'is_admin', 'roleid', 871 'lead_view', 'status', 'end_hour', 'is_owner', 872 'dayoftheweek', 'start_hour', 'date_format', 'hour_format', 'time_zone', 'activity_view', 'callduration', 873 'othereventduration', 'defaulteventstatus', 'defaultactivitytype', 'reminder_interval', 'calendarsharedtype',); 874 $sequence = 0; 875 $usersTabId = getTabId('Users'); 876 $blockIds = array(); 877 $blockIds[] = getBlockId($usersTabId, 'LBL_USERLOGIN_ROLE'); 878 $blockIds[] = getBlockId($usersTabId, 'LBL_CALENDAR_SETTINGS'); 879 880 $updateQuery = "UPDATE vtiger_field SET sequence = CASE fieldname "; 881 foreach($userFields as $fieldName) { 882 if($fieldName == 'dayoftheweek') { 883 $sequence = 0; 884 } 885 $updateQuery .= " WHEN '$fieldName' THEN ". ++$sequence ; 886 } 887 $updateQuery .= " END WHERE tabid = $usersTabId AND block IN (". generateQuestionMarks($blockIds) .")"; 888 889 Migration_Index_View::ExecuteQuery($updateQuery, $blockIds); 890 891 echo "<br>User Fields Sequence Updated"; 892 893 // updating Emails module in sharing access rules 894 $EmailsTabId = getTabId('Emails'); 895 $query = "SELECT tabid FROM vtiger_def_org_share"; 896 $result = $adb->pquery($query, array()); 897 $resultCount = $adb->num_rows($result); 898 $exist = false; 899 for($i=0; $i<$resultCount;$i++){ 900 $tabid = $adb->query_result($result, $i, 'tabid'); 901 if($tabid == $EmailsTabId){ 902 $exist = true; 903 echo 'Emails Sharing Access entry already exist'; 904 break; 905 } 906 } 907 908 if(!$exist){ 909 $ruleid = $adb->getUniqueID('vtiger_def_org_share'); 910 $shareaccessquery = "INSERT INTO vtiger_def_org_share VALUES(?,?,?,?)"; 911 $result = Migration_Index_View::ExecuteQuery($shareaccessquery, array($ruleid, $EmailsTabId, 2, 0)); 912 echo 'Emails Sharing Access entry is added'; 913 } 914 //90 ends 915 916 //91 starts 917 $pathToFile = "layouts/vlayout/modules/Products/PopupContents.tpl"; 918 shell_exec("rm -rf $pathToFile"); 919 echo "Removed Products PopupContents.tpl"; 920 echo "<br>"; 921 922 $pathToFile = "layouts/vlayout/modules/Products/PopupEntries.tpl"; 923 shell_exec("rm -rf $pathToFile"); 924 echo "Removed Products PopupEntries.tpl"; 925 echo "<br>"; 926 //91 ends 927 928 //92 starts 929 $result = $adb->pquery('SELECT max(templateid) AS maxtemplateid FROM vtiger_emailtemplates', array()); 930 Migration_Index_View::ExecuteQuery('UPDATE vtiger_emailtemplates_seq SET id = ?', array(1 + ((int)$adb->query_result($result, 0, 'maxtemplateid')))); 931 932 $result = $adb->pquery("SELECT 1 FROM vtiger_eventhandlers WHERE event_name=? AND handler_class=?", 933 array('vtiger.entity.aftersave','Vtiger_RecordLabelUpdater_Handler')); 934 if($adb->num_rows($result) <= 0) { 935 $lastMaxCRMId = 0; 936 do { 937 $rs = $adb->pquery("SELECT crmid,setype FROM vtiger_crmentity WHERE crmid > ? LIMIT 500", array($lastMaxCRMId)); 938 if (!$adb->num_rows($rs)) { 939 break; 940 } 941 942 while ($row = $adb->fetch_array($rs)) { 943 $imageType = stripos($row['setype'], 'image'); 944 $attachmentType = stripos($row['setype'], 'attachment'); 945 946 /** 947 * TODO: Optimize underlying API to cache re-usable data, for speedy data. 948 */ 949 if($attachmentType || $imageType) { 950 $labelInfo = $row['setype']; 951 } else { 952 $labelInfo = getEntityName($row['setype'], array(intval($row['crmid']))); 953 } 954 955 if ($labelInfo) { 956 $label = html_entity_decode($labelInfo[$row['crmid']],ENT_QUOTES); 957 958 Migration_Index_View::ExecuteQuery('UPDATE vtiger_crmentity SET label=? WHERE crmid=? AND setype=?', 959 array($label, $row['crmid'], $row['setype'])); 960 } 961 962 if (intval($row['crmid']) > $lastMaxCRMId) { 963 $lastMaxCRMId = intval($row['crmid']); 964 } 965 } 966 $rs = null; 967 unset($rs); 968 } while(true); 969 970 $homeModule = Vtiger_Module::getInstance('Home'); 971 Vtiger_Event::register($homeModule, 'vtiger.entity.aftersave', 'Vtiger_RecordLabelUpdater_Handler', 'modules/Vtiger/handlers/RecordLabelUpdater.php'); 972 echo "Record Update Handler was updated successfully"; 973 } 974 // To update the Campaign related status value in database as in language file 975 $updateQuery = "update vtiger_campaignrelstatus set campaignrelstatus=? where campaignrelstatus=?"; 976 Migration_Index_View::ExecuteQuery($updateQuery,array('Contacted - Unsuccessful' , 'Contacted - Unsuccessful')); 977 echo 'Campaign related status value is updated'; 978 //92 ends 979 980 //93 starts 981 //93 ends 982 983 //94 starts 984 $result = $adb->pquery('SELECT 1 FROM vtiger_currencies WHERE currency_name = ?', array('Libya, Dinar')); 985 if(!$adb->num_rows($result)) { 986 Migration_Index_View::ExecuteQuery('INSERT INTO vtiger_currencies (currencyid, currency_name, currency_code, currency_symbol) VALUES(?, ?, ?, ?)', 987 array($adb->getUniqueID('vtiger_currencies'), 'Libya, Dinar', 'LYD', 'LYD')); 988 } 989 990 //Start: Customer - Feature #17656 Allow users to add/remove date format with the date fields in workflow send mail task. 991 $fieldResult = $adb->pquery('SELECT fieldname, name, typeofdata FROM vtiger_field 992 INNER JOIN vtiger_tab ON vtiger_tab.tabid = vtiger_field.tabid WHERE typeofdata LIKE ?', array('D%')); 993 994 $dateFieldsList = $dateTimeFieldsList = array(); 995 while ($rowData = $adb->fetch_array($fieldResult)) { 996 $moduleName = $rowData['name']; 997 $fieldName = $rowData['fieldname']; 998 999 $pos = stripos($rowData['typeofdata'], 'DT'); 1000 if ($pos !== false) { 1001 $dateTimeFieldsList[$moduleName][$fieldName] = $fieldName; 1002 } else { 1003 $dateFieldsList[$moduleName][$fieldName] = $fieldName; 1004 } 1005 } 1006 unset($dateFieldsList['Events']['due_date']); 1007 $dateTimeFieldsList['Events']['due_date'] = 'due_date'; 1008 1009 $dateFields = array(); 1010 foreach ($dateFieldsList as $moduleName => $fieldNamesList) { 1011 $dateFields = array_merge($dateFields, $fieldNamesList); 1012 } 1013 1014 $dateTimeFields = array(); 1015 foreach ($dateTimeFieldsList as $moduleName => $fieldNamesList) { 1016 $dateTimeFields = array_merge($dateTimeFields, $fieldNamesList); 1017 } 1018 1019 $taskIdsList = array(); 1020 $result = $adb->pquery('SELECT task_id, module_name FROM com_vtiger_workflowtasks 1021 INNER JOIN com_vtiger_workflows ON com_vtiger_workflows.workflow_id = com_vtiger_workflowtasks.workflow_id 1022 WHERE task LIKE ?', array('%VTEmailTask%')); 1023 while ($rowData = $adb->fetch_array($result)) { 1024 $taskIdsList[$rowData['task_id']] = $rowData['module_name']; 1025 } 1026 1027 $dateFormat = '($_DATE_FORMAT_)'; 1028 $timeZone = '($(general : (__VtigerMeta__) usertimezone))'; 1029 foreach ($taskIdsList as $taskId => $taskModuleName) { 1030 $tm = new VTTaskManager($adb); 1031 $task = $tm->retrieveTask($taskId); 1032 1033 $emailTask = new VTEmailTask(); 1034 $properties = get_object_vars($task); 1035 foreach ($properties as $propertyName => $propertyValue) { 1036 $propertyValue = str_replace('$(general : (__VtigerMeta__) date)', "(general : (__VtigerMeta__) date) $dateFormat", $propertyValue); 1037 1038 foreach ($dateFields as $fieldName) { 1039 if ($taskModuleName === 'Events' && $fieldName === 'due_date') { 1040 continue; 1041 } 1042 $propertyValue = str_replace("$$fieldName", "$$fieldName $dateFormat", $propertyValue); 1043 } 1044 1045 foreach ($dateTimeFields as $fieldName) { 1046 if ($taskModuleName === 'Calendar' && $fieldName === 'due_date') { 1047 continue; 1048 } 1049 $propertyValue = str_replace("$$fieldName", "$$fieldName $timeZone", $propertyValue); 1050 } 1051 1052 foreach ($dateFieldsList as $moduleName => $fieldNamesList) { 1053 foreach ($fieldNamesList as $fieldName) { 1054 $propertyValue = str_replace("($moduleName) $fieldName)", "($moduleName) $fieldName) $dateFormat", $propertyValue); 1055 } 1056 } 1057 foreach ($dateTimeFieldsList as $moduleName => $fieldNamesList) { 1058 foreach ($fieldNamesList as $fieldName) { 1059 $propertyValue = str_replace("($moduleName) $fieldName)", "($moduleName) $fieldName) $timeZone", $propertyValue); 1060 } 1061 } 1062 $emailTask->$propertyName = $propertyValue; 1063 } 1064 $tm->saveTask($emailTask); 1065 } 1066 1067 1068 1069 global $root_directory; 1070 1071 // To update vtiger_modcomments table for permormance issue 1072 $datatypeQuery = "ALTER TABLE vtiger_modcomments MODIFY COLUMN related_to int(19)"; 1073 $dtresult = Migration_Index_View::ExecuteQuery($datatypeQuery, array()); 1074 if($dtresult){ 1075 echo 'ModComments related_to field Datatype updated'; 1076 }else{ 1077 echo 'Failed to update Modcomments Datatype'; 1078 } 1079 echo '</br>'; 1080 $indexQuery = "ALTER TABLE vtiger_modcomments ADD INDEX relatedto_idx (related_to)"; 1081 $indexResult = Migration_Index_View::ExecuteQuery($indexQuery, array()); 1082 if($indexResult){ 1083 echo 'Index added on ModComments'; 1084 }else{ 1085 echo 'Failed to add index on ModComments'; 1086 } 1087 // End 1088 1089 $maxActionIdResult = $adb->pquery('SELECT MAX(actionid) AS maxid FROM vtiger_actionmapping', array()); 1090 $maxActionId = $adb->query_result($maxActionIdResult, 0, 'maxid'); 1091 Migration_Index_View::ExecuteQuery('INSERT INTO vtiger_actionmapping(actionid, actionname, securitycheck) VALUES(?,?,?)', array($maxActionId+1 ,'Print', '0')); 1092 echo "<br> added print to vtiger_actionnmapping"; 1093 $module = Vtiger_Module_Model::getInstance('Reports'); 1094 $module->enableTools(Array('Print', 'Export')); 1095 echo "<br> enabled Print and export"; 1096 1097 //94 ends 1098 1099 //95 starts 1100 Migration_Index_View::ExecuteQuery('ALTER TABLE vtiger_webforms MODIFY COLUMN description TEXT',array()); 1101 require_once 'vtlib/Vtiger/Module.php'; 1102 $module = Vtiger_Module::getInstance('Users'); 1103 if ($module) { 1104 $blockInstance = Vtiger_Block::getInstance('LBL_CALENDAR_SETTINGS', $module); 1105 if ($blockInstance) { 1106 $hideCompletedField = Vtiger_Field::getInstance('hidecompletedevents', $module); 1107 if(!$hideCompletedField){ 1108 $fieldInstance = new Vtiger_Field(); 1109 $fieldInstance->name = 'hidecompletedevents'; 1110 $fieldInstance->label = 'LBL_HIDE_COMPLETED_EVENTS'; 1111 $fieldInstance->uitype = 56; 1112 $fieldInstance->column = $fieldInstance->name; 1113 $fieldInstance->columntype = 'INT'; 1114 $fieldInstance->typeofdata = 'C~O'; 1115 $fieldInstance->diplaytype = '1'; 1116 $fieldInstance->defaultvalue = '0'; 1117 $blockInstance->addField($fieldInstance); 1118 echo '<br>Hide/Show, completed/held, events/todo FIELD ADDED IN USERS'; 1119 } 1120 } 1121 } 1122 1123 $entityModulesModels = Vtiger_Module_Model::getEntityModules(); 1124 $modules = array(); 1125 if($entityModulesModels){ 1126 foreach($entityModulesModels as $model){ 1127 $modules[] = $model->getName(); 1128 } 1129 } 1130 1131 foreach($modules as $module){ 1132 $moduleInstance = Vtiger_Module::getInstance($module); 1133 if($moduleInstance){ 1134 $result = Migration_Index_View::ExecuteQuery("select blocklabel from vtiger_blocks where tabid=? and sequence = ?", array($moduleInstance->id, 1)); 1135 $block = $adb->query_result($result,0,'blocklabel'); 1136 if($block){ 1137 $blockInstance = Vtiger_Block::getInstance($block, $moduleInstance); 1138 $field = new Vtiger_Field(); 1139 $field->name = 'created_user_id'; 1140 $field->label = 'Created By'; 1141 $field->table = 'vtiger_crmentity'; 1142 $field->column = 'smcreatorid'; 1143 $field->uitype = 53; 1144 $field->typeofdata = 'V~O'; 1145 $field->displaytype= 2; 1146 $field->quickcreate = 3; 1147 $field->masseditable = 0; 1148 $blockInstance->addField($field); 1149 echo "Creator field added for $module"; 1150 echo '<br>'; 1151 } 1152 }else{ 1153 echo "Unable to find $module instance"; 1154 echo '<br>'; 1155 } 1156 } 1157 Migration_Index_View::ExecuteQuery("UPDATE vtiger_field SET presence=0 WHERE fieldname='unit_price' and columnname='unit_price'", array()); 1158 Migration_Index_View::ExecuteQuery("ALTER TABLE vtiger_portal ADD createdtime datetime", array()); 1159 1160 $adb->query("CREATE TABLE IF NOT EXISTS vtiger_calendar_default_activitytypes (id INT(19), module VARCHAR(50), fieldname VARCHAR(50), defaultcolor VARCHAR(50));"); 1161 1162 $result = Migration_Index_View::ExecuteQuery('SELECT * FROM vtiger_calendar_default_activitytypes', array()); 1163 if ($adb->num_rows($result) <= 0) { 1164 $calendarViewTypes = array('Events' => array('Events'=>'#17309A'), 1165 'Calendar' => array('Tasks'=>'#3A87AD'), 1166 'Potentials' => array('Potentials'=>'#AA6705'), 1167 'Contacts' => array('support_end_date'=>'#953B39', 1168 'birthday'=>'#545252'), 1169 'Invoice' => array('Invoice'=>'#87865D'), 1170 'Project' => array('Project'=>'#C71585'), 1171 'ProjectTask' => array('Project Task'=>'#006400'), 1172 ); 1173 1174 foreach($calendarViewTypes as $module=>$viewInfo) { 1175 foreach($viewInfo as $fieldname=>$color) { 1176 Migration_Index_View::ExecuteQuery('INSERT INTO vtiger_calendar_default_activitytypes (id, module, fieldname, defaultcolor) VALUES (?,?,?,?)', array($adb->getUniqueID('vtiger_calendar_default_activitytypes'), $module, $fieldname, $color)); 1177 } 1178 } 1179 echo '<br>Default Calendar view types added to the table.<br>'; 1180 } 1181 $adb->query("CREATE TABLE IF NOT EXISTS vtiger_calendar_user_activitytypes (id INT(19), defaultid INT(19), userid INT(19), color VARCHAR(50), visible INT(19) default 1);"); 1182 1183 $result = Migration_Index_View::ExecuteQuery('SELECT * FROM vtiger_calendar_user_activitytypes', array()); 1184 if ($adb->num_rows($result) <= 0) { 1185 $queryResult = Migration_Index_View::ExecuteQuery('SELECT id, defaultcolor FROM vtiger_calendar_default_activitytypes', array()); 1186 $numRows = $adb->num_rows($queryResult); 1187 for ($i = 0; $i < $numRows; $i++) { 1188 $row = $adb->query_result_rowdata($queryResult, $i); 1189 $activityIds[$row['id']] = $row['defaultcolor']; 1190 } 1191 1192 $allUsers = Users_Record_Model::getAll(true); 1193 foreach($allUsers as $userId=>$userModel) { 1194 foreach($activityIds as $activityId=>$color) { 1195 Migration_Index_View::ExecuteQuery('INSERT INTO vtiger_calendar_user_activitytypes (id, defaultid, userid, color) VALUES (?,?,?,?)', array($adb->getUniqueID('vtiger_calendar_user_activitytypes'), $activityId, $userId, $color)); 1196 } 1197 } 1198 echo '<br>Default Calendar view types added to the table for all existing users'; 1199 } 1200 1201 Migration_Index_View::ExecuteQuery("UPDATE vtiger_field SET quickcreate = ? WHERE tabid = 8 AND (fieldname = ? OR fieldname = ?);", array(0,"filename","filelocationtype")); 1202 1203 //95 ends 1204 1205 //96 starts 1206 $entityModulesModels = Vtiger_Module_Model::getEntityModules(); 1207 $fieldNameToDelete = 'created_user_id'; 1208 if($entityModulesModels){ 1209 foreach($entityModulesModels as $moduleInstance){ 1210 if($moduleInstance){ 1211 $module = $moduleInstance->name; 1212 $fieldInstance = Vtiger_Field::getInstance($fieldNameToDelete,$moduleInstance); 1213 if($fieldInstance){ 1214 $fieldInstance->delete(); 1215 echo "<br>"; 1216 echo "For $module created by is removed"; 1217 }else{ 1218 echo "<br>"; 1219 echo "For $module created by is not there"; 1220 } 1221 1222 }else{ 1223 echo "Unable to find $module instance"; 1224 echo '<br>'; 1225 } 1226 } 1227 } 1228 //96 ends 1229 1230 //97 starts 1231 $adb = PearDatabase::getInstance(); 1232 $handlers = array('modules/FieldFormulas/VTFieldFormulasEventHandler.inc'); 1233 Migration_Index_View::ExecuteQuery('DELETE FROM vtiger_eventhandlers WHERE handler_path IN ('.generateQuestionMarks($handlers) .')', $handlers); 1234 1235 //delete modtracker detail view links 1236 Migration_Index_View::ExecuteQuery('DELETE FROM vtiger_links WHERE linktype = ? AND handler_class = ? AND linkurl like "javascript:ModTrackerCommon.showhistory%"', 1237 array('DETAILVIEWBASIC', 'ModTracker')); 1238 1239 //Added New field in mailmanager 1240 Migration_Index_View::ExecuteQuery('ALTER TABLE vtiger_mail_accounts ADD COLUMN sent_folder VARCHAR(50)', array()); 1241 echo '<br>selected folder field added in mailmanager.<br>'; 1242 1243 //97 ends 1244 1245 //Migrating PBXManager 5.4.0 to 6.x 1246 if(!defined('INSTALLATION_MODE')) { 1247 $moduleInstance = Vtiger_Module_Model::getInstance('PBXManager'); 1248 if(!$moduleInstance){ 1249 echo '<br>Installing PBX Manager starts<br>'; 1250 installVtlibModule('PBXManager', 'packages/vtiger/mandatory/PBXManager.zip'); 1251 }else{ 1252 $result = $adb->pquery('SELECT server, port FROM vtiger_asterisk', array()); 1253 $server = $adb->query_result($result, 0, 'server'); 1254 1255 $qualifiedModuleName = 'PBXManager'; 1256 $recordModel = Settings_PBXManager_Record_Model::getCleanInstance(); 1257 $recordModel->set('gateway', $qualifiedModuleName); 1258 1259 $connector = new PBXManager_PBXManager_Connector; 1260 foreach ($connector->getSettingsParameters() as $field => $type) { 1261 $fieldValue = ""; 1262 if ($field == "webappurl") { 1263 $fieldValue = "http://" . $server . ":"; 1264 } 1265 if ($field == "vtigersecretkey") { 1266 $fieldValue = uniqid(rand()); 1267 } 1268 $recordModel->set($field, $fieldValue); 1269 } 1270 $recordModel->save(); 1271 1272 $modules = array('Contacts', 'Accounts', 'Leads'); 1273 $recordModel = new PBXManager_Record_Model; 1274 1275 foreach ($modules as $module) { 1276 $moduleInstance = CRMEntity::getInstance($module); 1277 1278 $query = $moduleInstance->buildSearchQueryForFieldTypes(array('11')); 1279 $result = $adb->pquery($query, array()); 1280 $rows = $adb->num_rows($result); 1281 1282 for ($i = 0; $i < $rows; $i++) { 1283 $row = $adb->query_result_rowdata($result, $i); 1284 $crmid = $row['id']; 1285 1286 foreach ($row as $name => $value) { 1287 $values = array(); 1288 $values['crmid'] = $crmid; 1289 $values['setype'] = $module; 1290 1291 if ($name != 'name' && !empty($value) && $name != 'id' && !is_numeric($name) 1292 && $name != 'firstname' && $name != 'lastname') { 1293 $values[$name] = $value; 1294 $recordModel->receivePhoneLookUpRecord($name, $values, true); 1295 } 1296 } 1297 } 1298 } 1299 //Data migrate from old columns to new columns in vtiger_pbxmanager 1300 $query = 'SELECT * FROM vtiger_pbxmanager'; 1301 $result = $adb->pquery($query, array()); 1302 $params = array(); 1303 $rowCount = $adb->num_rows($result); 1304 for ($i = 0; $i < $rowCount; $i++) { 1305 $pbxmanagerid = $adb->query_result($result, $i, 'pbxmanagerid'); 1306 $callfrom = $adb->query_result($result, $i, 'callfrom'); 1307 $callto = $adb->query_result($result, $i, 'callto'); 1308 $timeofcall = $adb->query_result($result, $i, 'timeofcall'); 1309 $status = $adb->query_result($result, $i, 'status'); 1310 $customer = PBXManager_Record_Model::lookUpRelatedWithNumber($callfrom); 1311 $userIdQuery = $adb->pquery('SELECT userid FROM vtiger_asteriskextensions WHERE asterisk_extension = ?', array($callto)); 1312 $user = $adb->query_result($userIdQuery, $i, 'userid'); 1313 if ($status == 'outgoing') { 1314 $callstatus = 'outbound'; 1315 } else if ($status == 'incoming') { 1316 $callstatus = 'inbound'; 1317 } 1318 //Update query 1319 $adb->pquery('UPDATE vtiger_pbxmanager SET customer = ? AND user = ? AND totalduration = ? AND callstatus = ? WHERE pbxmanagerid = ?', array($customer, $user, $timeofcall, $callstatus, $pbxmanagerid)); 1320 } 1321 1322 //Adding PBXManager PostUpdate API's 1323 //Add user extension field 1324 1325 $module = Vtiger_Module::getInstance('Users'); 1326 if ($module) { 1327 $module->initTables(); 1328 $blockInstance = Vtiger_Block::getInstance('LBL_MORE_INFORMATION', $module); 1329 if ($blockInstance) { 1330 $fieldInstance = new Vtiger_Field(); 1331 $fieldInstance->name = 'phone_crm_extension'; 1332 $fieldInstance->label = 'CRM Phone Extension'; 1333 $fieldInstance->uitype = 11; 1334 $fieldInstance->typeofdata = 'V~O'; 1335 $blockInstance->addField($fieldInstance); 1336 } 1337 } 1338 echo '<br>Added PBXManager User extension field.<br>'; 1339 //Query to fetch asterisk extension 1340 $extensionResult = $adb->pquery('SELECT userid, asterisk_extension FROM vtiger_asteriskextensions', array()); 1341 for ($i = 0; $i < $adb->num_rows($extensionResult); $i++) { 1342 $userId = $adb->query_result($extensionResult, 0, 'userid'); 1343 $extensionNumber = $adb->query_result($extensionResult, 0, 'asterisk_extension'); 1344 $adb->pquery('UPDATE vtiger_users SET phone_crm_extension = ? WHERE id = ?', array($extensionNumber, $userId)); 1345 } 1346 //Add PBXManager Links 1347 1348 $handlerInfo = array('path' => 'modules/PBXManager/PBXManager.php', 1349 'class' => 'PBXManager', 1350 'method' => 'checkLinkPermission'); 1351 $headerScriptLinkType = 'HEADERSCRIPT'; 1352 $incomingLinkLabel = 'Incoming Calls'; 1353 Vtiger_Link::addLink(0, $headerScriptLinkType, $incominglinkLabel, 'modules/PBXManager/resources/PBXManagerJS.js', '', '', $handlerInfo); 1354 echo '<br>Added PBXManager links<br>'; 1355 1356 //Add settings links 1357 1358 $adb = PearDatabase::getInstance(); 1359 $integrationBlock = $adb->pquery('SELECT * FROM vtiger_settings_blocks WHERE label=?', array('LBL_INTEGRATION')); 1360 $integrationBlockCount = $adb->num_rows($integrationBlock); 1361 1362 // To add Block 1363 if ($integrationBlockCount > 0) { 1364 $blockid = $adb->query_result($integrationBlock, 0, 'blockid'); 1365 } else { 1366 $blockid = $adb->getUniqueID('vtiger_settings_blocks'); 1367 $sequenceResult = $adb->pquery("SELECT max(sequence) as sequence FROM vtiger_settings_blocks", array()); 1368 if ($adb->num_rows($sequenceResult)) { 1369 $sequence = $adb->query_result($sequenceResult, 0, 'sequence'); 1370 } 1371 $adb->pquery("INSERT INTO vtiger_settings_blocks(blockid, label, sequence) VALUES(?,?,?)", array($blockid, 'LBL_INTEGRATION', ++$sequence)); 1372 } 1373 1374 // To add a Field 1375 $fieldid = $adb->getUniqueID('vtiger_settings_field'); 1376 $adb->pquery("INSERT INTO vtiger_settings_field(fieldid, blockid, name, iconpath, description, linkto, sequence, active) 1377 VALUES(?,?,?,?,?,?,?,?)", array($fieldid, $blockid, 'LBL_PBXMANAGER', '', 'PBXManager module Configuration', 'index.php?module=PBXManager&parent=Settings&view=Index', 2, 0)); 1378 1379 echo '<br>Added PBXManager settings links<br>'; 1380 1381 //Add module related dependencies 1382 1383 $pbxmanager = Vtiger_Module::getInstance('PBXManager'); 1384 $dependentModules = array('Contacts', 'Leads', 'Accounts'); 1385 foreach ($dependentModules as $module) { 1386 $moduleInstance = Vtiger_Module::getInstance($module); 1387 $moduleInstance->setRelatedList($pbxmanager, "PBXManager", array(), 'get_dependents_list'); 1388 } 1389 1390 echo '<br>Added PBXManager related list<br>'; 1391 1392 //Add action mapping 1393 1394 $adb = PearDatabase::getInstance(); 1395 $module = new Vtiger_Module(); 1396 $moduleInstance = $module->getInstance('PBXManager'); 1397 1398 //To add actionname as ReceiveIncomingcalls 1399 $maxActionIdresult = $adb->pquery('SELECT max(actionid+1) AS actionid FROM vtiger_actionmapping', array()); 1400 if ($adb->num_rows($maxActionIdresult)) { 1401 $actionId = $adb->query_result($maxActionIdresult, 0, 'actionid'); 1402 } 1403 $adb->pquery('INSERT INTO vtiger_actionmapping 1404 (actionid, actionname, securitycheck) VALUES(?,?,?)', array($actionId, 'ReceiveIncomingCalls', 0)); 1405 $moduleInstance->enableTools('ReceiveIncomingcalls'); 1406 1407 //To add actionname as MakeOutgoingCalls 1408 $maxActionIdresult = $adb->pquery('SELECT max(actionid+1) AS actionid FROM vtiger_actionmapping', array()); 1409 if ($adb->num_rows($maxActionIdresult)) { 1410 $actionId = $adb->query_result($maxActionIdresult, 0, 'actionid'); 1411 } 1412 $adb->pquery('INSERT INTO vtiger_actionmapping 1413 (actionid, actionname, securitycheck) VALUES(?,?,?)', array($actionId, 'MakeOutgoingCalls', 0)); 1414 $moduleInstance->enableTools('MakeOutgoingCalls'); 1415 1416 echo '<br>Added PBXManager action mapping<br>'; 1417 1418 //Add lookup events 1419 1420 $adb = PearDatabase::getInstance(); 1421 $EventManager = new VTEventsManager($adb); 1422 $createEvent = 'vtiger.entity.aftersave'; 1423 $deleteEVent = 'vtiger.entity.afterdelete'; 1424 $restoreEvent = 'vtiger.entity.afterrestore'; 1425 $batchSaveEvent = 'vtiger.batchevent.save'; 1426 $batchDeleteEvent = 'vtiger.batchevent.delete'; 1427 $handler_path = 'modules/PBXManager/PBXManagerHandler.php'; 1428 $className = 'PBXManagerHandler'; 1429 $batchEventClassName = 'PBXManagerBatchHandler'; 1430 $EventManager->registerHandler($createEvent, $handler_path, $className, '', '["VTEntityDelta"]'); 1431 $EventManager->registerHandler($deleteEVent, $handler_path, $className); 1432 $EventManager->registerHandler($restoreEvent, $handler_path, $className); 1433 $EventManager->registerHandler($batchSaveEvent, $handler_path, $batchEventClassName); 1434 $EventManager->registerHandler($batchDeleteEvent, $handler_path, $batchEventClassName); 1435 1436 echo 'Added PBXManager lookup events'; 1437 1438 //Existing Asterisk extension block removed from vtiger_users if exist 1439 $moduleInstance = Vtiger_Module_Model::getInstance('Users'); 1440 $fieldInstance = $moduleInstance->getField('asterisk_extension'); 1441 1442 if (!empty($fieldInstance)) { 1443 $blockId = $fieldInstance->getBlockId(); 1444 $fieldInstance->delete(); 1445 } 1446 1447 $fieldInstance = $moduleInstance->getField('use_asterisk'); 1448 if (!empty($fieldInstance)) { 1449 $fieldInstance->delete(); 1450 } 1451 } 1452 } 1453 1454 //Hiding previous PBXManager fields. 1455 $tabId = getTabid('PBXManager'); 1456 Migration_Index_View::ExecuteQuery("UPDATE vtiger_field SET presence=? WHERE tabid=? AND fieldname=?;", array(1, $tabId, "callfrom")); 1457 Migration_Index_View::ExecuteQuery("UPDATE vtiger_field SET presence=? WHERE tabid=? AND fieldname=?;", array(1, $tabId, "callto")); 1458 Migration_Index_View::ExecuteQuery("UPDATE vtiger_field SET presence=? WHERE tabid=? AND fieldname=?;", array(1, $tabId, "timeofcall")); 1459 Migration_Index_View::ExecuteQuery("UPDATE vtiger_field SET presence=? WHERE tabid=? AND fieldname=?;", array(1, $tabId, "status")); 1460 echo '<br>Hiding previous PBXManager fields done.<br>'; 1461 //PBXManager porting ends. 1462 1463 //Making document module fields masseditable 1464 Migration_Index_View::ExecuteQuery("UPDATE vtiger_field SET masseditable = ? WHERE tabid = 8 AND fieldname = ?;", array(1,"notes_title")); 1465 Migration_Index_View::ExecuteQuery("UPDATE vtiger_field SET masseditable = ? WHERE tabid = 8 AND fieldname = ?;", array(1,"assigned_user_id")); 1466 Migration_Index_View::ExecuteQuery("UPDATE vtiger_field SET masseditable = ? WHERE tabid = 8 AND fieldname = ?;", array(1,"notecontent")); 1467 Migration_Index_View::ExecuteQuery("UPDATE vtiger_field SET masseditable = ? WHERE tabid = 8 AND fieldname = ?;", array(1,"fileversion")); 1468 Migration_Index_View::ExecuteQuery("UPDATE vtiger_field SET masseditable = ? WHERE tabid = 8 AND fieldname = ?;", array(1,"filestatus")); 1469 Migration_Index_View::ExecuteQuery("UPDATE vtiger_field SET masseditable = ? WHERE tabid = 8 AND fieldname = ?;", array(1,"folderid")); 1470 1471 //Add Vat ID to Company Details 1472 Vtiger_Utils::AddColumn('vtiger_organizationdetails', 'vatid', 'VARCHAR(100)'); 1473 1474 //Add Column trial for vtiger_tab table if not exists 1475 $result = $adb->pquery("SHOW COLUMNS FROM vtiger_tab LIKE ?", array('trial')); 1476 if (!($adb->num_rows($result))) { 1477 $adb->pquery("ALTER TABLE vtiger_tab ADD trial INT(1) NOT NULL DEFAULT 0",array()); 1478 } 1479 1480 ##--http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/7635--## 1481 //Avoid premature deletion of activity related records 1482 $moduleArray = array('Accounts', 'Leads', 'HelpDesk', 'Campaigns', 'Potentials', 'PurchaseOrder', 'SalesOrder', 'Quotes', 'Invoice'); 1483 $relatedToQuery = "SELECT fieldid FROM vtiger_field WHERE tabid=? AND fieldname=?"; 1484 $calendarInstance = Vtiger_Module::getInstance('Calendar'); 1485 $tabId = $calendarInstance->getId(); 1486 $result = $adb->pquery($relatedToQuery, array($tabId, 'parent_id')); 1487 $fieldId = $adb->query_result($result,0, 'fieldid'); 1488 $insertQuery = "INSERT INTO vtiger_fieldmodulerel (fieldid,module,relmodule,status,sequence) VALUES(?,?,?,?,?)"; 1489 $relModule = 'Calendar'; 1490 foreach ($moduleArray as $module) { 1491 $adb->pquery($insertQuery, array($fieldId, $module, $relModule, NULL, NULL)); 1492 } 1493 //For contacts the fieldname is contact_id 1494 $contactsRelatedToQuery = "SELECT fieldid FROM vtiger_field WHERE tabid=? AND fieldname=?"; 1495 $contactsResult = $adb->pquery($contactsRelatedToQuery, array($tabId, 'contact_id')); 1496 $contactsFieldId = $adb->query_result($contactsResult,0, 'fieldid'); 1497 $insertContactsQuery = "INSERT INTO vtiger_fieldmodulerel (fieldid,module,relmodule,status,sequence) VALUES(?,?,?,?,?)"; 1498 $module = 'Contacts'; 1499 $adb->pquery($insertContactsQuery, array($contactsFieldId, $module, $relModule, NULL, NULL)); 1500 1501 ##--http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/7635--## 1502 1503 1504 //Adding is_owner to existing vtiger users 1505 1506 $usersModuleInstance = Vtiger_Module::getInstance('Users'); 1507 $usersBlockInstance = Vtiger_Block::getInstance('LBL_USERLOGIN_ROLE', $usersModuleInstance); 1508 1509 $usersFieldInstance = Vtiger_Field::getInstance('is_owner', $usersModuleInstance); 1510 if (!$usersFieldInstance) { 1511 $field = new Vtiger_Field(); 1512 $field->name = 'is_owner'; 1513 $field->label = 'Account Owner'; 1514 $field->column = 'is_owner'; 1515 $field->table = 'vtiger_users'; 1516 $field->uitype = 1; 1517 $field->typeofdata = 'V~O'; 1518 $field->readonly = '0'; 1519 $field->displaytype = '5'; 1520 $field->masseditable = '0'; 1521 $field->quickcreate = '0'; 1522 $field->columntype = 'VARCHAR(5)'; 1523 $field->defaultvalue = 0; 1524 $usersBlockInstance->addField($field); 1525 echo '<br> Added isOwner field in Users'; 1526 } 1527 1528 //Setting up is_owner for every admin user of CRM 1529 $adb = PearDatabase::getInstance(); 1530 $idResult = $adb->pquery('SELECT id FROM vtiger_users WHERE is_admin = ? AND status=?', array('on', 'Active')); 1531 if ($adb->num_rows($idResult) > 0) { 1532 for($i = 0;$i<=$adb->num_rows($idResult);$i++) { 1533 $userid = $adb->query_result($idResult, $i, 'id'); 1534 $adb->pquery('UPDATE vtiger_users SET is_owner=? WHERE id=?', array(1, $userid)); 1535 echo '<br>Account Owner Informnation saved in vtiger'; 1536 //Recreate user prvileges 1537 createUserPrivilegesfile($userId); 1538 echo '<br>User previleges file recreated aftter adding is_owner field'; 1539 } 1540 }else { 1541 echo '<br>Account Owner was not existed in this database'; 1542 } 1543 1544 //Reports Chart Supported 1545 Migration_Index_View::ExecuteQuery("CREATE TABLE IF NOT EXISTS vtiger_reporttype( 1546 reportid INT(10), 1547 data text, 1548 PRIMARY KEY (`reportid`), 1549 CONSTRAINT `fk_1_vtiger_reporttype` FOREIGN KEY (`reportid`) REFERENCES `vtiger_report` (`reportid`) ON DELETE CASCADE) 1550 ENGINE=InnoDB DEFAULT CHARSET=utf8;", array()); 1551 1552 //Configuration Editor fix 1553 $sql = "UPDATE vtiger_settings_field SET name = ? WHERE name = ?"; 1554 Migration_Index_View::ExecuteQuery($sql,array('LBL_CONFIG_EDITOR', 'Configuration Editor'));
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |