Example #1
0
    public function process(Vtiger_Request $request)
    {
        $currentUser = Users_Record_Model::getCurrentUserModel();
        $viewer = $this->getViewer($request);
        $moduleName = $request->getModule();
        $qualifiedModuleName = $request->getModule(false);
        $recordId = $request->get('task_id');
        $workflowId = $request->get('for_workflow');
        $workflowModel = Settings_Workflows_Record_Model::getInstance($workflowId);
        $taskTypes = $workflowModel->getTaskTypes();
        if ($recordId) {
            $taskModel = Settings_Workflows_TaskRecord_Model::getInstance($recordId);
        } else {
            $taskType = $request->get('type');
            if (empty($taskType)) {
                $taskType = !empty($taskTypes[0]) ? $taskTypes[0]->getName() : 'VTEmailTask';
            }
            $taskModel = Settings_Workflows_TaskRecord_Model::getCleanInstance($workflowModel, $taskType);
        }
        $taskTypeModel = $taskModel->getTaskType();
        $viewer->assign('TASK_TYPE_MODEL', $taskTypeModel);
        $viewer->assign('TASK_TEMPLATE_PATH', $taskTypeModel->getTemplatePath());
        $recordStructureInstance = Settings_Workflows_RecordStructure_Model::getInstanceForWorkFlowModule($workflowModel, Settings_Workflows_RecordStructure_Model::RECORD_STRUCTURE_MODE_EDITTASK);
        $viewer->assign('RECORD_STRUCTURE_MODEL', $recordStructureInstance);
        $viewer->assign('RECORD_STRUCTURE', $recordStructureInstance->getStructure());
        $moduleModel = $workflowModel->getModule();
        $dateTimeFields = $moduleModel->getFieldsByType(array('date', 'datetime'));
        $taskObject = $taskModel->getTaskObject();
        $taskType = get_class($taskObject);
        if ($taskType === 'VTCreateEntityTask') {
            if ($taskObject->entity_type) {
                $relationModuleModel = Vtiger_Module_Model::getInstance($taskObject->entity_type);
                $ownerFieldModels = $relationModuleModel->getFieldsByType('owner');
                $fieldMapping = Zend_Json::decode($taskObject->field_value_mapping);
                foreach ($fieldMapping as $key => $mappingInfo) {
                    if (array_key_exists($mappingInfo['fieldname'], $ownerFieldModels)) {
                        $userRecordModel = Users_Record_Model::getInstanceByName($mappingInfo['value']);
                        if ($userRecordModel) {
                            $ownerName = $userRecordModel->getId();
                        } else {
                            $groupRecordModel = Settings_Groups_Record_Model::getInstance($mappingInfo['value']);
                            $ownerName = $groupRecordModel->getId();
                        }
                        $fieldMapping[$key]['value'] = $ownerName;
                    }
                }
                $taskObject->field_value_mapping = Zend_Json::encode($fieldMapping);
            }
        }
        if ($taskType === 'VTUpdateFieldsTask') {
            if ($moduleModel->getName() == "Documents") {
                $restrictFields = array('folderid', 'filename', 'filelocationtype');
                $viewer->assign('RESTRICTFIELDS', $restrictFields);
            }
        }
        $viewer->assign('SOURCE_MODULE', $moduleModel->getName());
        $viewer->assign('MODULE_MODEL', $moduleModel);
        $viewer->assign('TASK_ID', $recordId);
        $viewer->assign('WORKFLOW_ID', $workflowId);
        $viewer->assign('DATETIME_FIELDS', $dateTimeFields);
        $viewer->assign('WORKFLOW_MODEL', $workflowModel);
        $viewer->assign('TASK_TYPES', $taskTypes);
        $viewer->assign('TASK_MODEL', $taskModel);
        $viewer->assign('CURRENTDATE', date('Y-n-j'));
        $metaVariables = Settings_Workflows_Module_Model::getMetaVariables();
        if ($moduleModel->getName() == 'Invoice' || $moduleModel->getName() == 'Quotes') {
            $metaVariables['Portal Pdf Url'] = '(general : (__VtigerMeta__) portalpdfurl)';
        }
        // Adding option Line Item block for Individual tax mode
        $individualTaxBlockLabel = vtranslate("LBL_LINEITEM_BLOCK_GROUP", $qualifiedModuleName);
        $individualTaxBlockValue = $viewer->view('LineItemsGroupTemplate.tpl', $qualifiedModuleName, $fetch = true);
        // Adding option Line Item block for group tax mode
        $groupTaxBlockLabel = vtranslate("LBL_LINEITEM_BLOCK_INDIVIDUAL", $qualifiedModuleName);
        $groupTaxBlockValue = $viewer->view('LineItemsIndividualTemplate.tpl', $qualifiedModuleName, $fetch = true);
        $templateVariables = array($individualTaxBlockValue => $individualTaxBlockLabel, $groupTaxBlockValue => $groupTaxBlockLabel);
        $viewer->assign('META_VARIABLES', $metaVariables);
        $viewer->assign('TEMPLATE_VARIABLES', $templateVariables);
        $viewer->assign('TASK_OBJECT', $taskObject);
        $viewer->assign('FIELD_EXPRESSIONS', Settings_Workflows_Module_Model::getExpressions());
        $repeat_date = $taskModel->getTaskObject()->calendar_repeat_limit_date;
        if (!empty($repeat_date)) {
            $repeat_date = Vtiger_Date_UIType::getDisplayDateValue($repeat_date);
        }
        $viewer->assign('REPEAT_DATE', $repeat_date);
        $userModel = Users_Record_Model::getCurrentUserModel();
        $viewer->assign('dateFormat', $userModel->get('date_format'));
        $viewer->assign('timeFormat', $userModel->get('hour_format'));
        $viewer->assign('MODULE', $moduleName);
        $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName);
        $emailFields = $recordStructureInstance->getAllEmailFields();
        foreach ($emailFields as $metaKey => $emailField) {
            $emailFieldoptions .= '<option value=",$' . $metaKey . '">' . $emailField->get('workflow_columnlabel') . '</option>';
        }
        $nameFields = $recordStructureInstance->getNameFields();
        $fromEmailFieldOptions = '<option value="">' . vtranslate('Optional', $qualifiedModuleName) . '</option>';
        $fromEmailFieldOptions .= '<option value="$(general : (__VtigerMeta__) supportName)<$(general : (__VtigerMeta__) supportEmailId)>"
									>' . vtranslate('LBL_HELPDESK_SUPPORT_EMAILID', $qualifiedModuleName) . '</option>';
        foreach ($emailFields as $metaKey => $emailField) {
            list($relationFieldName, $rest) = explode(' ', $metaKey);
            $value = '<$' . $metaKey . '>';
            if ($nameFields) {
                $nameFieldValues = '';
                foreach (array_keys($nameFields) as $fieldName) {
                    if (strstr($fieldName, $relationFieldName) || count(explode(' ', $metaKey)) === 1 && count(explode(' ', $fieldName)) === 1) {
                        $fieldName = '$' . $fieldName;
                        $nameFieldValues .= ' ' . $fieldName;
                    }
                }
                $value = trim($nameFieldValues) . $value;
            }
            $fromEmailFieldOptions .= '<option value="' . $value . '">' . $emailField->get('workflow_columnlabel') . '</option>';
        }
        $structure = $recordStructureInstance->getStructure();
        // for inventory modules we shouldn't show item detail fields
        if ($taskType == "VTEmailTask" && in_array($workflowModel->getModule()->name, getInventoryModules())) {
            $itemsBlock = "LBL_ITEM_DETAILS";
            unset($structure[$itemsBlock]);
        }
        foreach ($structure as $fields) {
            foreach ($fields as $field) {
                $allFieldoptions .= '<option value="$' . $field->get('workflow_columnname') . '">' . $field->get('workflow_columnlabel') . '</option>';
            }
        }
        $userList = $currentUser->getAccessibleUsers();
        $groupList = $currentUser->getAccessibleGroups();
        $assignedToValues = array();
        $assignedToValues[vtranslate('LBL_USERS', 'Vtiger')] = $userList;
        $assignedToValues[vtranslate('LBL_GROUPS', 'Vtiger')] = $groupList;
        $viewer->assign('ASSIGNED_TO', $assignedToValues);
        $viewer->assign('EMAIL_FIELD_OPTION', $emailFieldoptions);
        $viewer->assign('FROM_EMAIL_FIELD_OPTION', $fromEmailFieldOptions);
        $viewer->assign('ALL_FIELD_OPTIONS', $allFieldoptions);
        $viewer->view('EditTask.tpl', $qualifiedModuleName);
    }
Example #2
0
 public function Save(Vtiger_Request $request)
 {
     $workflowId = $request->get('for_workflow');
     if (!empty($workflowId)) {
         $record = $request->get('task_id');
         if ($record) {
             $taskRecordModel = Settings_Workflows_TaskRecord_Model::getInstance($record);
         } else {
             $workflowModel = Settings_Workflows_Record_Model::getInstance($workflowId);
             $taskRecordModel = Settings_Workflows_TaskRecord_Model::getCleanInstance($workflowModel, $request->get('taskType'));
         }
         $taskObject = $taskRecordModel->getTaskObject();
         $taskObject->summary = $request->get("summary");
         $active = $request->get("active");
         if ($active == "true") {
             $taskObject->active = true;
         } else {
             if ($active == "false") {
                 $taskObject->active = false;
             }
         }
         $checkSelectDate = $request->get('check_select_date');
         if (!empty($checkSelectDate)) {
             $trigger = array('days' => ($request->get('select_date_direction') == 'after' ? 1 : -1) * (int) $request->get('select_date_days'), 'field' => $request->get('select_date_field'));
             $taskObject->trigger = $trigger;
         } else {
             $taskObject->trigger = null;
         }
         $fieldNames = $taskObject->getFieldNames();
         foreach ($fieldNames as $fieldName) {
             if ($fieldName == 'field_value_mapping') {
                 $taskObject->{$fieldName} = $request->getRaw($fieldName);
             } else {
                 $taskObject->{$fieldName} = $request->get($fieldName);
             }
             if ($fieldName == 'calendar_repeat_limit_date') {
                 $taskObject->{$fieldName} = DateTimeField::convertToDBFormat($request->get($fieldName));
             }
         }
         $taskType = get_class($taskObject);
         if ($taskType === 'VTCreateEntityTask') {
             $relationModuleModel = Vtiger_Module_Model::getInstance($taskObject->entity_type);
             $ownerFieldModels = $relationModuleModel->getFieldsByType('owner');
             $fieldMapping = Zend_Json::decode($taskObject->field_value_mapping);
             foreach ($fieldMapping as $key => $mappingInfo) {
                 if (array_key_exists($mappingInfo['fieldname'], $ownerFieldModels)) {
                     $userRecordModel = Users_Record_Model::getInstanceById($mappingInfo['value'], 'Users');
                     $ownerName = $userRecordModel->get('user_name');
                     if (!$ownerName) {
                         $groupRecordModel = Settings_Groups_Record_Model::getInstance($mappingInfo['value']);
                         $ownerName = $groupRecordModel->getName();
                     }
                     $fieldMapping[$key]['value'] = $ownerName;
                 }
             }
             $taskObject->field_value_mapping = Zend_Json::encode($fieldMapping);
         }
         $taskRecordModel->save();
         $response = new Vtiger_Response();
         $response->setResult(array('for_workflow' => $workflowId));
         $response->emit();
     }
 }
Example #3
0
 public function getTasks($active = false)
 {
     return Settings_Workflows_TaskRecord_Model::getAllForWorkflow($this, $active);
 }
Example #4
0
    public function databaseData()
    {
        global $log, $adb;
        $log->debug("Entering YetiForceUpdate::databaseData() method ...");
        $this->addFields();
        $adb->query("UPDATE vtiger_eventhandlers_seq SET `id` = (SELECT MAX(eventhandler_id) FROM `vtiger_eventhandlers`);");
        $result = $adb->pquery("SELECT * FROM `vtiger_eventhandlers` WHERE event_name = ? AND handler_class = ?;", array('vtiger.entity.link.after', 'HelpDeskHandler'));
        if ($adb->num_rows($result) == 0) {
            $addHandler = array();
            $addHandler[] = array('vtiger.entity.link.after', 'modules/HelpDesk/handlers/HelpDeskHandler.php', 'HelpDeskHandler', '', '1', '[]');
            $em = new VTEventsManager($adb);
            foreach ($addHandler as $handler) {
                $em->registerHandler($handler[0], $handler[1], $handler[2], $handler[3], $handler[5]);
            }
        }
        $template[] = array('Notify Owner On Ticket Change', 'HelpDesk', 'PLL_RECORD');
        $template[] = array('Notify Account On Ticket Change', 'HelpDesk', 'PLL_RECORD');
        $template[] = array('Notify Contact On Ticket Closed', 'HelpDesk', 'PLL_RECORD');
        $template[] = array('Notify Account On Ticket Closed', 'HelpDesk', 'PLL_RECORD');
        $template[] = array('Notify Contact On Ticket Create', 'HelpDesk', 'PLL_RECORD');
        $template[] = array('Notify Account On Ticket Create', 'HelpDesk', 'PLL_RECORD');
        $template[] = array('Notify Contact On Ticket Change', 'HelpDesk', 'PLL_RECORD');
        $template[] = array('Notify Owner On Ticket Closed', 'HelpDesk', 'PLL_RECORD');
        $template[] = array('Notify Owner On Ticket Create', 'HelpDesk', 'PLL_RECORD');
        $template[] = array('Customer Portal Login Details', 'Contacts', 'PLL_RECORD');
        $template[] = array('Send invitations', 'Events', 'PLL_RECORD');
        $template[] = array('Send Notification Email to Record Owner', 'Calendar', 'PLL_RECORD');
        $template[] = array('Activity Reminder Notification', 'Calendar', 'PLL_RECORD');
        $template[] = array('Activity Reminder Notification', 'Events', 'PLL_RECORD');
        $template[] = array('Test mail about the mail server configuration.', 'Users', 'PLL_RECORD');
        $template[] = array('ForgotPassword', 'Users', 'PLL_RECORD');
        $template[] = array('Customer Portal - ForgotPassword', 'Contacts', 'PLL_RECORD');
        $template[] = array('New comment added to ticket from portal', 'ModComments', 'PLL_RECORD');
        $template[] = array('New comment added to ticket', 'ModComments', 'PLL_RECORD');
        $template[] = array('Security risk has been detected - Brute Force', 'Contacts', 'PLL_MODULE');
        $template[] = array('Backup has been made', 'Contacts', 'PLL_MODULE');
        $result = $adb->query("SHOW COLUMNS FROM `vtiger_ossmailtemplates` LIKE 'ossmailtemplates_type';");
        if ($adb->num_rows($result) == 1) {
            foreach ($template as $temp) {
                $adb->pquery("UPDATE `vtiger_ossmailtemplates` set ossmailtemplates_type = ? WHERE `name` = ? AND oss_module_list = ? ", array($temp[2], $temp[0], $temp[1]));
            }
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('OSSMailTemplates'), getTabid('Documents'), 'get_attachments', 'Documents'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Documents');
            $target_Module = Vtiger_Module::getInstance('OSSMailTemplates');
            $target_Module->setRelatedList($moduleInstance, 'Documents', array('add,select'), 'get_attachments');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('HelpDesk'), getTabid('Contacts'), 'get_related_list', 'Contacts'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Contacts');
            $target_Module = Vtiger_Module::getInstance('HelpDesk');
            $target_Module->setRelatedList($moduleInstance, 'Contacts', array('SELECT'), 'get_related_list');
        }
        $adb->pquery("UPDATE `vtiger_field` set displaytype = ? WHERE `columnname` = ?;", array(2, 'was_read'));
        $adb->pquery("UPDATE `vtiger_field` set uitype = ? WHERE `columnname` = ? AND tablename = ?;", array(15, 'industry', 'vtiger_leaddetails'));
        $adb->pquery("UPDATE `vtiger_calendar_default_activitytypes` set active = ? ;", array(1));
        $adb->pquery("UPDATE `com_vtiger_workflows` SET `type` = ? WHERE `summary` = ? AND module_name = ? ;", array('[]', 'Ticket Creation: Send Email to Record Contact', 'HelpDesk'));
        $result = $adb->pquery("SELECT workflow_id FROM `com_vtiger_workflows` WHERE summary = ? AND module_name =? ", array('Send Customer Login Details', 'Contacts'));
        if ($adb->num_rows($result) == 1) {
            $workflow_id = $adb->query_result_raw($result, 0, 'workflow_id');
            $workflowTaskAdd = array(128, 53, 'Mark portal users password as sent.', 'O:18:"VTEntityMethodTask":7:{s:18:"executeImmediately";b:1;s:10:"workflowId";s:2:"53";s:7:"summary";s:35:"Mark portal users password as sent.";s:6:"active";b:0;s:7:"trigger";N;s:10:"methodName";s:16:"MarkPasswordSent";s:2:"id";i:128;}');
            $result = $adb->pquery("SELECT * FROM `com_vtiger_workflowtasks` WHERE summary = ? AND workflow_id =? ", array($workflowTaskAdd[2], $workflow_id));
            if ($adb->num_rows($result) == 0) {
                $taskManager = new VTTaskManager($adb);
                $task = $taskManager->unserializeTask($workflowTaskAdd[3]);
                $task->id = '';
                $task->workflowId = $workflow_id;
                $taskManager->saveTask($task);
            }
        }
        $adb->pquery('UPDATE com_vtiger_workflows SET defaultworkflow = "0" WHERE `summary` = ? AND module_name = ?;', array('Ticket Creation: Send Email to Record Contact', 'HelpDesk'));
        $result = $adb->pquery('SELECT * FROM com_vtiger_workflows WHERE `summary` = ? AND module_name = ?;', array('Ticket Creation: Send Email to Record Contact', 'HelpDesk'));
        for ($i = 0; $i < $adb->num_rows($result); $i++) {
            $recordId = $adb->query_result($result, $i, 'workflow_id');
            $adb->pquery("DELETE FROM com_vtiger_workflowtasks WHERE workflow_id IN\n\t\t\t\t\t\t\t(SELECT workflow_id FROM com_vtiger_workflows WHERE workflow_id=? AND (defaultworkflow IS NULL OR defaultworkflow != 1))", array($recordId));
            $adb->pquery("DELETE FROM com_vtiger_workflows WHERE workflow_id=? AND (defaultworkflow IS NULL OR defaultworkflow != 1)", array($recordId));
        }
        $result = $adb->pquery('SELECT * FROM com_vtiger_workflowtasks WHERE `summary` IN (?,?);', array('Notify Contact On Ticket Closed', 'Notify Contact On Ticket Change'));
        for ($i = 0; $i < $adb->num_rows($result); $i++) {
            $recordId = $adb->query_result($result, $i, 'task_id');
            $adb->pquery("delete from com_vtiger_workflowtasks where task_id=?", array($recordId));
        }
        $task_entity_method[] = array('HelpDesk', 'HeldDeskChangeNotifyContacts', 'modules/HelpDesk/workflows/HelpDeskWorkflow.php', 'HeldDeskChangeNotifyContacts');
        $task_entity_method[] = array('HelpDesk', 'HeldDeskClosedNotifyContacts', 'modules/HelpDesk/workflows/HelpDeskWorkflow.php', 'HeldDeskClosedNotifyContacts');
        $emm = new VTEntityMethodManager($adb);
        foreach ($task_entity_method as $method) {
            $result = $adb->pquery("SELECT * FROM `com_vtiger_workflowtasks_entitymethod` WHERE method_name = ? ", array($method[1]));
            if ($adb->num_rows($result) == 0) {
                $emm->addEntityMethod($method[0], $method[1], $method[2], $method[3]);
            }
        }
        $adb->pquery('UPDATE com_vtiger_workflows SET test = ? WHERE `summary` = ? AND module_name = ?;', array('[{"fieldname":"ticketstatus","operation":"has changed","value":null,"valuetype":"rawtext","joincondition":"and","groupjoin":"and","groupid":"0"},{"fieldname":"ticketstatus","operation":"is","value":"Closed","valuetype":"rawtext","joincondition":"","groupjoin":"and","groupid":"0"}]', 'Ticket Closed: Send Email to Record Contact', 'HelpDesk'));
        $adb->pquery('UPDATE com_vtiger_workflows SET test = ? WHERE `summary` = ? AND module_name = ?;', array('[{"fieldname":"ticketstatus","operation":"has changed","value":null,"valuetype":"rawtext","joincondition":"and","groupjoin":"and","groupid":"0"},{"fieldname":"ticketstatus","operation":"is not","value":"Closed","valuetype":"rawtext","joincondition":"","groupjoin":"and","groupid":"0"}]', 'Ticket change: Send Email to Record Contact', 'HelpDesk'));
        $result = $adb->pquery("SELECT workflow_id FROM `com_vtiger_workflows` WHERE summary = ? AND module_name =? ", array('Ticket change: Send Email to Record Contact', 'HelpDesk'));
        if ($adb->num_rows($result) == 1) {
            $workflow_id = $adb->query_result_raw($result, 0, 'workflow_id');
            $workflowTaskAdd = array(133, 26, 'Notify Contact On Ticket Change', 'O:18:"VTEntityMethodTask":7:{s:18:"executeImmediately";b:1;s:10:"workflowId";s:2:"26";s:7:"summary";s:31:"Notify Contact On Ticket Change";s:6:"active";b:0;s:7:"trigger";N;s:10:"methodName";s:28:"HeldDeskChangeNotifyContacts";s:2:"id";i:133;}');
            $result = $adb->pquery("SELECT * FROM `com_vtiger_workflowtasks` WHERE summary = ? AND workflow_id =? ", array($workflowTaskAdd[2], $workflow_id));
            if ($adb->num_rows($result) == 0) {
                $taskManager = new VTTaskManager($adb);
                $task = $taskManager->unserializeTask($workflowTaskAdd[3]);
                $task->id = '';
                $task->workflowId = $workflow_id;
                $taskManager->saveTask($task);
            }
        }
        $result = $adb->pquery("SELECT workflow_id FROM `com_vtiger_workflows` WHERE summary = ? AND module_name =? ", array('Ticket Closed: Send Email to Record Contact', 'HelpDesk'));
        if ($adb->num_rows($result) == 1) {
            $workflow_id = $adb->query_result_raw($result, 0, 'workflow_id');
            $workflowTaskAdd = array(134, 29, 'Notify contacts about closing of ticket.', 'O:18:"VTEntityMethodTask":7:{s:18:"executeImmediately";b:1;s:10:"workflowId";s:2:"29";s:7:"summary";s:40:"Notify contacts about closing of ticket.";s:6:"active";b:0;s:7:"trigger";N;s:10:"methodName";s:28:"HeldDeskClosedNotifyContacts";s:2:"id";i:134;}');
            $result = $adb->pquery("SELECT * FROM `com_vtiger_workflowtasks` WHERE summary = ? AND workflow_id =? ", array($workflowTaskAdd[2], $workflow_id));
            if ($adb->num_rows($result) == 0) {
                $taskManager = new VTTaskManager($adb);
                $task = $taskManager->unserializeTask($workflowTaskAdd[3]);
                $task->id = '';
                $task->workflowId = $workflow_id;
                $taskManager->saveTask($task);
            }
        }
        $this->settingsReplace();
        $this->picklists();
        $result = $adb->pquery("SELECT * FROM `yetiforce_mail_config` WHERE name = ? ", array('showMailAccounts'));
        if ($adb->num_rows($result) == 0) {
            $adb->query("insert  into `yetiforce_mail_config`(`type`,`name`,`value`) values ('mailIcon','showMailAccounts','false');");
        }
        $result = $adb->pquery("SELECT * FROM `yetiforce_mail_config` WHERE name = ? ", array('showNumberUnreadEmails'));
        if ($adb->num_rows($result) == 0) {
            $adb->query("insert  into `yetiforce_mail_config`(`type`,`name`,`value`) values ('mailIcon','showNumberUnreadEmails','false');");
        }
        $result = $adb->pquery("SELECT * FROM `yetiforce_mail_config` WHERE name = ? ", array('showMailIcon'));
        if ($adb->num_rows($result) == 0) {
            $adb->query("insert  into `yetiforce_mail_config`(`type`,`name`,`value`) values ('mailIcon','showMailIcon','true');");
        }
        $result = $adb->pquery("SELECT * FROM `yetiforce_mail_config` WHERE name = ? ", array('timeCheckingMail'));
        if ($adb->num_rows($result) == 0) {
            $result = $adb->pquery("SELECT * FROM `vtiger_ossmailscanner_config` WHERE conf_type = ? AND `parameter` = ? ;", array('email_list', 'time_checking_mail'));
            $value = $adb->query_result($result, 0, 'value');
            if (!$value) {
                $value = 30;
            }
            $adb->pquery("insert  into `yetiforce_mail_config`(`type`,`name`,`value`) values ('mailIcon','timeCheckingMail',?);", array($value));
        }
        $result = $adb->pquery("SELECT * FROM `yetiforce_mail_config` WHERE name = ? ", array('autologinActive'));
        if ($adb->num_rows($result) == 0) {
            $result = $adb->pquery("SELECT * FROM `vtiger_ossmailscanner_config` WHERE conf_type = ? AND `parameter` = ? ;", array('email_list', 'autologon'));
            $value = $adb->query_result($result, 0, 'value');
            if (!$value) {
                $value = 'false';
            }
            $adb->pquery("insert  into `yetiforce_mail_config`(`type`,`name`,`value`) values ('autologin','autologinActive',?);", array('false'));
        }
        $result = $adb->pquery('SELECT * FROM `yetiforce_mail_config` WHERE type = ? AND name = ?;', array('signature', 'signature'));
        if ($adb->num_rows($result) == 0) {
            $adb->query("insert  into `yetiforce_mail_config`(`type`,`name`,`value`) values ('signature','signature','');");
        }
        $result = $adb->pquery('SELECT * FROM `yetiforce_mail_config` WHERE type = ? AND name = ?;', array('signature', 'addSignature'));
        if ($adb->num_rows($result) == 0) {
            $adb->query("insert  into `yetiforce_mail_config`(`type`,`name`,`value`) values ('signature','addSignature','false');");
        }
        $adb->pquery("DELETE FROM vtiger_ossmailscanner_config WHERE conf_type = ? AND `parameter` = ? ;", array('email_list', 'autologon'));
        $adb->pquery("DELETE FROM vtiger_ossmailscanner_config WHERE conf_type = ? AND `parameter` = ? ;", array('email_list', 'time_checking_mail'));
        $adb->pquery("UPDATE `com_vtiger_workflows` SET `test` = ? WHERE `summary` = ? ;", array('[{"fieldname":"ticketstatus","operation":"has changed","value":null,"valuetype":"rawtext","joincondition":"and","groupjoin":"and","groupid":"0"},{"fieldname":"ticketstatus","operation":"is not","value":"Closed","valuetype":"rawtext","joincondition":"and","groupjoin":"and","groupid":"0"},{"fieldname":"(assigned_user_id : (Users) emailoptout)","operation":"is","value":"1","valuetype":"rawtext","joincondition":"","groupjoin":"and","groupid":"0"}]', 'Ticket change: Send Email to Record Owner'));
        $adb->pquery("UPDATE `com_vtiger_workflows` SET `test` = ? WHERE `summary` = ? ;", array('[{"fieldname":"ticketstatus","operation":"has changed","value":null,"valuetype":"rawtext","joincondition":"and","groupjoin":"and","groupid":"0"},{"fieldname":"ticketstatus","operation":"is","value":"Closed","valuetype":"rawtext","joincondition":"and","groupjoin":"and","groupid":"0"},{"fieldname":"(assigned_user_id : (Users) emailoptout)","operation":"is","value":"1","valuetype":"rawtext","joincondition":"","groupjoin":"and","groupid":"0"}]', 'Ticket Closed: Send Email to Record Owner'));
        $result = $adb->pquery("SELECT * FROM `com_vtiger_workflowtasks` WHERE summary = ? ", array('Update Closed Time'));
        if ($adb->num_rows($result) == 1) {
            $task_id = $adb->query_result($result, 0, 'task_id');
            $taskRecordModel = Settings_Workflows_TaskRecord_Model::getInstance($task_id);
            $taskObject = $taskRecordModel->getTaskObject();
            $taskObject->active = false;
            $taskRecordModel->save();
        }
        $adb->pquery('UPDATE `vtiger_field` SET uitype = ? WHERE tabid = ? AND columnname = ? ;', array(19, getTabid('Emails'), 'description'));
        $adb->pquery('UPDATE `vtiger_field` SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?  AND tabid =?;', [3, 'vtiger_activity', 'date_start', getTabid('Calendar')]);
        $adb->pquery('UPDATE `vtiger_field` SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?  AND tabid =?;', [10, 'vtiger_activity', 'date_start', getTabid('Events')]);
        $adb->pquery('UPDATE `vtiger_field` SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid =?;', [4, 'vtiger_activity', 'due_date', getTabid('Calendar')]);
        $adb->pquery('UPDATE `vtiger_field` SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid =?;', [11, 'vtiger_activity', 'due_date', getTabid('Events')]);
        $adb->pquery('UPDATE `vtiger_field` SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [1, 'vtiger_contactdetails', 'firstname']);
        $adb->pquery('UPDATE `vtiger_field` SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [5, 'vtiger_contactdetails', 'parentid']);
        $adb->pquery('UPDATE `vtiger_field` SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [3, 'vtiger_contactdetails', 'email']);
        $adb->pquery('UPDATE `vtiger_field` SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [6, 'vtiger_contactdetails', 'smownerid']);
        $result = $adb->pquery("SELECT * FROM `vtiger_support_processes`;");
        if ($adb->num_rows($result) == 0) {
            $adb->query("insert  into `vtiger_support_processes`(`id`,`ticket_status_indicate_closing`) values (1,'');");
        }
        $result = $adb->pquery('SELECT quickcreatesequence FROM `vtiger_field` WHERE tablename = ? AND columnname = ? AND tabid =?;', array('vtiger_seactivityrel', 'crmid', getTabid('Calendar')));
        $result2 = $adb->pquery('SELECT quickcreatesequence FROM `vtiger_field` WHERE tablename = ? AND columnname = ? AND tabid =?;', array('vtiger_seactivityrel', 'crmid', getTabid('Events')));
        if ($adb->num_rows($result) == 1) {
            $quickcreatesequence = $adb->query_result($result, 0, 'quickcreatesequence');
            $adb->pquery('UPDATE `vtiger_field` SET columnname=?,tablename=?,fieldname=?,fieldlabel=?, quickcreate=? WHERE tablename = ? AND columnname = ? ;', ['process', 'vtiger_activity', 'process', 'Process', '1', 'vtiger_seactivityrel', 'crmid']);
            $adb->pquery('UPDATE `vtiger_field` SET columnname=?,tablename=?,fieldname=?,fieldlabel=?, quickcreate=?, uitype=?, quickcreatesequence=?, summaryfield=? WHERE tablename = ? AND columnname = ? AND tabid = ?;', ['link', 'vtiger_activity', 'link', 'Relation', '2', '67', $quickcreatesequence, '1', 'vtiger_cntactivityrel', 'contactid', getTabid('Calendar')]);
            $quickcreatesequence = $adb->query_result($result2, 0, 'quickcreatesequence');
            $adb->pquery('UPDATE `vtiger_field` SET columnname=?,tablename=?,fieldname=?,fieldlabel=?, quickcreate=?, uitype=?, quickcreatesequence=?, summaryfield=? WHERE tablename = ? AND columnname = ? AND tabid = ?;', ['link', 'vtiger_activity', 'link', 'Relation', '2', '67', $quickcreatesequence, '1', 'vtiger_cntactivityrel', 'contactid', getTabid('Events')]);
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_realization_process`;");
        if ($adb->num_rows($result) == 0) {
            $adb->pquery("INSERT INTO vtiger_realization_process(module_id, status_indicate_closing) VALUES(?,?)", array(getTabid('Project'), ''));
        }
        $adb->pquery("DELETE FROM vtiger_settings_field WHERE name = ?;", array('LBL_CONVERSION_TO_ACCOUNT'));
        $adb->pquery('UPDATE `vtiger_settings_field` SET `name` = ?, `description` = ?, `linkto` = ? WHERE `name` = ? AND `description` = ? ;', ['LBL_MENU_BUILDER', 'LBL_MENU_BUILDER_DESCRIPTION', 'index.php?module=Menu&view=Index&parent=Settings', 'Menu Manager', 'LBL_MENU_DESC']);
        $result = $adb->query("SELECT * FROM `yetiforce_auth`;");
        if ($adb->num_rows($result) == 0) {
            $adb->query("insert  into `yetiforce_auth`(`type`,`param`,`value`) values ('ldap','active','false');");
            $adb->query("insert  into `yetiforce_auth`(`type`,`param`,`value`) values ('ldap','server','testlab.local');");
            $adb->query("insert  into `yetiforce_auth`(`type`,`param`,`value`) values ('ldap','port','389');");
            $adb->pquery("insert  into `yetiforce_auth`(`type`,`param`,`value`) values (?,?,?);", ['ldap', 'users', NULL]);
        }
        $result = $adb->pquery("SELECT * FROM `yetiforce_auth` WHERE `param` = ?;", ['domain']);
        if ($adb->num_rows($result) == 0) {
            $adb->pquery("insert  into `yetiforce_auth`(`type`,`param`,`value`) values (?,?,?);", ['ldap', 'domain', NULL]);
        }
        $result = $adb->pquery("SELECT * FROM `yetiforce_menu`;");
        if ($adb->num_rows($result) == 0) {
            $menu[] = array(44, 0, 0, 2, 1, NULL, 'MEN_VIRTUAL_DESK', 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(45, 0, 44, 0, 0, getTabid('Home'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(46, 0, 44, 0, 1, getTabid('Calendar'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(47, 0, 0, 2, 2, NULL, 'MEN_LEADS', 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(48, 0, 47, 0, 0, getTabid('Leads'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(49, 0, 47, 0, 1, getTabid('Contacts'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(50, 0, 47, 0, 2, getTabid('Vendors'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(51, 0, 47, 0, 3, getTabid('Accounts'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(52, 0, 0, 2, 3, NULL, 'MEN_SALES', 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(54, 0, 52, 0, 0, getTabid('Campaigns'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(55, 0, 52, 0, 1, getTabid('Potentials'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(56, 0, 52, 0, 2, getTabid('QuotesEnquires'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(57, 0, 52, 0, 3, getTabid('RequirementCards'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(58, 0, 52, 0, 4, getTabid('Calculations'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(59, 0, 52, 0, 5, getTabid('Quotes'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(60, 0, 52, 0, 6, getTabid('SalesOrder'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(61, 0, 52, 0, 7, getTabid('PurchaseOrder'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(62, 0, 52, 0, 8, getTabid('PriceBooks'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(63, 0, 0, 2, 5, NULL, 'MEN_SUPPORT', 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(64, 0, 63, 0, 0, getTabid('HelpDesk'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(65, 0, 63, 0, 1, getTabid('ServiceContracts'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(66, 0, 63, 0, 2, getTabid('Faq'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(67, 0, 0, 2, 4, NULL, 'MEN_PROJECTS', 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(68, 0, 67, 0, 0, getTabid('Project'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(69, 0, 67, 0, 1, getTabid('ProjectMilestone'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(70, 0, 67, 0, 2, getTabid('ProjectTask'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(71, 0, 0, 2, 6, NULL, 'MEN_BOOKKEEPING', 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(72, 0, 71, 0, 3, getTabid('PaymentsIn'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(73, 0, 71, 0, 2, getTabid('PaymentsOut'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(74, 0, 71, 0, 1, getTabid('Invoice'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(75, 0, 71, 0, 0, getTabid('OSSCosts'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(76, 0, 0, 2, 7, NULL, 'MEN_HUMAN_RESOURCES', 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(77, 0, 76, 0, 0, getTabid('OSSEmployees'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(78, 0, 76, 0, 1, getTabid('OSSTimeControl'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(79, 0, 76, 0, 2, getTabid('HolidaysEntitlement'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(80, 0, 0, 2, 8, NULL, 'MEN_SECRETARY', 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(81, 0, 80, 0, 0, getTabid('LettersIn'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(82, 0, 80, 0, 1, getTabid('LettersOut'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(83, 0, 80, 0, 2, getTabid('Reservations'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(84, 0, 0, 2, 9, NULL, 'MEN_DATABESES', 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(85, 0, 84, 2, 0, NULL, 'MEN_PRODUCTBASE', 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(86, 0, 84, 0, 1, getTabid('Products'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(87, 0, 84, 0, 2, getTabid('OutsourcedProducts'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(88, 0, 84, 0, 3, getTabid('Assets'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(89, 0, 84, 3, 4, NULL, NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(90, 0, 84, 2, 5, NULL, 'MEN_SERVICESBASE', 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(91, 0, 84, 0, 6, getTabid('Services'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(92, 0, 84, 0, 7, getTabid('OSSOutsourcedServices'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(93, 0, 84, 0, 8, getTabid('OSSSoldServices'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(94, 0, 84, 3, 9, NULL, NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(95, 0, 84, 2, 10, NULL, 'MEN_LISTS', 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(96, 0, 84, 0, 11, getTabid('OSSMailView'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(97, 0, 84, 0, 12, getTabid('SMSNotifier'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(98, 0, 84, 0, 13, getTabid('PBXManager'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(99, 0, 84, 0, 14, getTabid('OSSMailTemplates'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(100, 0, 84, 0, 15, getTabid('Documents'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(102, 0, 84, 0, 16, getTabid('OSSPdf'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(106, 0, 84, 0, 18, getTabid('CallHistory'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(107, 0, 84, 3, 19, NULL, NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(108, 0, 84, 0, 21, getTabid('NewOrders'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(109, 0, 84, 0, 17, getTabid('OSSPasswords'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(110, 0, 0, 2, 10, NULL, 'MEN_TEAMWORK', 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(111, 0, 110, 0, 0, getTabid('Ideas'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(112, 0, 0, 6, 0, getTabid('Home'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(113, 0, 44, 0, 2, getTabid('OSSMail'), NULL, 0, NULL, 0, NULL, NULL, "");
            $menu[] = array(114, 0, 84, 0, 20, getTabid('Reports'), NULL, 0, NULL, 0, NULL, NULL, "");
            foreach ($menu as $m) {
                $adb->pquery("insert  into `yetiforce_menu`(`id`,`role`,`parentid`,`type`,`sequence`,`module`,`label`,`newwindow`,`dataurl`,`showicon`,`icon`,`sizeicon`,`hotkey`) values (" . generateQuestionMarks($m) . ");", array($m));
            }
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_links` WHERE linktype = ? AND linklabel = ? AND tabid = ? ;", ['DASHBOARDWIDGET', 'Calendar', getTabid('Home')]);
        if ($adb->num_rows($result) == 0) {
            $instanceModule = Vtiger_Module::getInstance('Home');
            $instanceModule->addLink('DASHBOARDWIDGET', 'Calendar', 'index.php?module=Home&view=ShowWidget&name=Calendar');
        }
        $adb->query('DROP TABLE IF EXISTS vtiger_converttoaccount_settings;');
        $adb->query('DROP TABLE IF EXISTS vtiger_marketing_processes;');
        $adb->query('DROP TABLE IF EXISTS vtiger_proc_marketing;');
        $adb->query('DROP TABLE IF EXISTS vtiger_salesprocesses_settings;');
        $adb->pquery('DELETE FROM vtiger_settings_field WHERE name = ?;', array('LBL_MDULES_COLOR_EDITOR'));
        $adb->query("CREATE TABLE IF NOT EXISTS `yetiforce_proc_marketing` (\n  `type` varchar(30) DEFAULT NULL,\n  `param` varchar(30) DEFAULT NULL,\n  `value` varchar(200) DEFAULT NULL,\n  KEY `type` (`type`,`param`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
        $adb->query("CREATE TABLE IF NOT EXISTS `yetiforce_proc_sales` (\n  `type` varchar(30) DEFAULT NULL,\n  `param` varchar(30) DEFAULT NULL,\n  `value` varchar(200) DEFAULT NULL,\n  KEY `type` (`type`,`param`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
        $result = $adb->pquery("SELECT * FROM `yetiforce_proc_marketing` WHERE type = ? AND param = ?;", ['conversion', 'change_owner']);
        if ($adb->num_rows($result) == 0) {
            $adb->query("insert  into `yetiforce_proc_marketing`(`type`,`param`,`value`) values ('conversion','change_owner','false');");
            $adb->query("insert  into `yetiforce_proc_marketing`(`type`,`param`,`value`) values ('lead','groups','');");
            $adb->query("insert  into `yetiforce_proc_marketing`(`type`,`param`,`value`) values ('lead','status','');");
            $adb->query("insert  into `yetiforce_proc_marketing`(`type`,`param`,`value`) values ('lead','currentuser_status','false');");
        }
        $result = $adb->pquery("SELECT * FROM `yetiforce_proc_sales` WHERE type = ? AND param = ?;", ['popup', 'limit_product_service']);
        if ($adb->num_rows($result) == 0) {
            $adb->query("insert  into `yetiforce_proc_sales`(`type`,`param`,`value`) values ('popup','limit_product_service','false');");
            $adb->query("insert  into `yetiforce_proc_sales`(`type`,`param`,`value`) values ('popup','update_shared_permissions','false');");
        }
        $result = $adb->pquery("SELECT * FROM `yetiforce_proc_sales` WHERE type = ? AND param = ?;", ['calculation', 'calculationsstatus']);
        if ($adb->num_rows($result) == 0) {
            $adb->query("insert  into `yetiforce_proc_sales`(`type`,`param`,`value`) values ('calculation','calculationsstatus','');");
            $adb->query("insert  into `yetiforce_proc_sales`(`type`,`param`,`value`) values ('potential','salesstage','');");
            $adb->query("insert  into `yetiforce_proc_sales`(`type`,`param`,`value`) values ('asset','assetstatus','');");
            $adb->query("insert  into `yetiforce_proc_sales`(`type`,`param`,`value`) values ('potential','add_potential','false');");
        }
        $adb->pquery('UPDATE `vtiger_settings_field` SET linkto = ? WHERE name = ?;', ['index.php?module=SalesProcesses&view=Index&parent=Settings', 'LBL_SALES_PROCESSES']);
        $result = $adb->pquery("SELECT * FROM `vtiger_eventhandlers` WHERE event_name = ? AND handler_class = ?;", ['vtiger.entity.link.after', 'Vtiger_SharingPrivileges_Handler']);
        if ($adb->num_rows($result) == 0) {
            $em = new VTEventsManager($adb);
            $em->registerHandler('vtiger.entity.link.after', 'modules/Vtiger/handlers/SharingPrivileges.php', 'Vtiger_SharingPrivileges_Handler');
        }
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [2, 'vtiger_projecttask', 'projectid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [4, 'vtiger_projecttask', 'startdate']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tabid = ? AND columnname = ? ;', [6, getTabid('ProjectTask'), 'smownerid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [7, 'vtiger_projecttask', 'projecttaskstatus']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [2, 'vtiger_projecttask', 'projectmilestoneid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [6, 'vtiger_projecttask', 'targetenddate']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [1, 'vtiger_requirementcards', 'subject']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [4, 'vtiger_requirementcards', 'requirementcards_status']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [3, 'vtiger_requirementcards', 'potentialid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tabid = ? AND columnname = ? ;', [2, getTabid('RequirementCards'), 'smownerid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [5, 'vtiger_requirementcards', 'quotesenquiresid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [9, 'vtiger_leadaddress', 'phone']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [4, 'vtiger_leaddetails', 'lastname']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [1, 'vtiger_leaddetails', 'company']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [8, 'vtiger_leaddetails', 'email']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [3, 'vtiger_leaddetails', 'leadstatus']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tabid = ? AND columnname = ? ;', [2, getTabid('Leads'), 'smownerid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [7, 'vtiger_leaddetails', 'vat_id']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [5, 'vtiger_leaddetails', 'leads_relation']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [6, 'vtiger_leaddetails', 'legal_form']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [3, 'vtiger_reservations', 'reservations_status']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tabid = ? AND columnname = ? ;', [4, getTabid('Reservations'), 'smownerid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [6, 'vtiger_reservations', 'date_start']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [5, 'vtiger_reservations', 'time_start']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [7, 'vtiger_reservations', 'time_end']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [8, 'vtiger_reservations', 'due_date']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [2, 'vtiger_reservations', 'type']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tabid = ? AND columnname = ? ;', [9, getTabid('Reservations'), 'description']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [1, 'vtiger_osspdf', 'title']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tabid = ? AND columnname = ? ;', [2, getTabid('OSSPdf'), 'smownerid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [10, 'vtiger_osspdf', 'osspdf_pdf_format']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [11, 'vtiger_osspdf', 'osspdf_pdf_orientation']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [8, 'vtiger_osspdf', 'osspdf_enable_footer']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [3, 'vtiger_osspdf', 'osspdf_enable_header']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [5, 'vtiger_osspdf', 'height_header']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [9, 'vtiger_osspdf', 'height_footer']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [4, 'vtiger_osspdf', 'selected']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [7, 'vtiger_osspdf', 'osspdf_view']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [6, 'vtiger_osspdf', 'moduleid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tabid = ? AND columnname = ? ;', [6, getTabid('Contacts'), 'smownerid']);
        $result = $adb->pquery("SELECT * FROM `vtiger_eventhandlers` WHERE handler_class = ?;", array('ProjectTaskHandler'));
        if ($adb->num_rows($result) == 0) {
            $em = new VTEventsManager($adb);
            $em->registerHandler('vtiger.entity.aftersave.final', 'modules/ProjectTask/handlers/ProjectTaskHandler.php', 'ProjectTaskHandler');
            $em->registerHandler('vtiger.entity.afterdelete', 'modules/ProjectTask/handlers/ProjectTaskHandler.php', 'ProjectTaskHandler');
            $em->registerHandler('vtiger.entity.afterrestore', 'modules/ProjectTask/handlers/ProjectTaskHandler.php', 'ProjectTaskHandler');
        }
        $adb->pquery('UPDATE vtiger_relatedlists SET label = ? WHERE label = ?;', ['Activities', 'Upcoming Activities']);
        $adb->pquery('DELETE FROM vtiger_relatedlists WHERE `tabid` IN (?,?,?,?,?,?,?,?) AND `label` = ?;', [getTabid('Accounts'), getTabid('Leads'), getTabid('Contacts'), getTabid('Potentials'), getTabid('HelpDesk'), getTabid('Campaigns'), getTabid('ServiceContracts'), getTabid('Project'), 'Activity History']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [4, 'vtiger_potential', 'related_to']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [5, 'vtiger_potential', 'closingdate']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? ;', [3, 'vtiger_potential', 'sales_stage']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [2, 'vtiger_crmentity', 'smownerid', 2]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [7, 'vtiger_osssoldservices', 'ssservicesstatus']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [9, 'vtiger_osssoldservices', 'pscategory']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [5, 'vtiger_osssoldservices', 'datesold']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [2, 'vtiger_crmentity', 'smownerid', getTabid('OSSSoldServices')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [3, 'vtiger_osssoldservices', 'invoiceid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [6, 'vtiger_osssoldservices', 'parent_id']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [4, 'vtiger_osssoldservices', 'serviceid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [3, 'vtiger_paymentsin', 'paymentsname']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [2, 'vtiger_crmentity', 'smownerid', getTabid('PaymentsIn')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [8, 'vtiger_paymentsin', 'paymentsin_status']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [7, 'vtiger_paymentsin', 'relatedid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [6, 'vtiger_paymentsin', 'salesid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [1, 'vtiger_paymentsin', 'paymentsvalue']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [5, 'vtiger_paymentsin', 'paymentstitle']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [4, 'vtiger_paymentsin', 'bank_account']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [1, 'vtiger_lettersin', 'title']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [2, 'vtiger_crmentity', 'smownerid', getTabid('LettersIn')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [1, 'vtiger_lettersout', 'title']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [2, 'vtiger_crmentity', 'smownerid', getTabid('LettersOut')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [1, 'vtiger_quotesenquires', 'subject']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [4, 'vtiger_quotesenquires', 'potentialid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [2, 'vtiger_crmentity', 'smownerid', getTabid('QuotesEnquires')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [3, 'vtiger_quotesenquires', 'quotesenquires_stage']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [5, 'vtiger_account', 'phone']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [4, 'vtiger_account', 'website']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [2, 'vtiger_crmentity', 'smownerid', getTabid('Accounts')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [3, 'vtiger_vendor', 'phone']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [4, 'vtiger_vendor', 'email']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [2, 'vtiger_crmentity', 'smownerid', getTabid('Vendors')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [2, 'vtiger_osstimecontrol', 'osstimecontrol_status']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [6, 'vtiger_osstimecontrol', 'date_start']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [5, 'vtiger_osstimecontrol', 'time_start']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [7, 'vtiger_osstimecontrol', 'time_end']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [8, 'vtiger_osstimecontrol', 'due_date']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [3, 'vtiger_osstimecontrol', 'timecontrol_type']);
        $adb->pquery('UPDATE vtiger_field SET sequence = ? WHERE tablename = ? AND columnname = ?;', [3, 'vtiger_ossemployees', 'private_phone']);
        $adb->pquery('UPDATE vtiger_field SET sequence = ? WHERE tablename = ? AND columnname = ?;', [2, 'vtiger_ossemployees', 'business_mail']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [9, 'vtiger_crmentity', 'description', getTabid('OSSTimeControl')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [2, 'vtiger_holidaysentitlement', 'holidaysentitlement_year']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ?, quickcreate = ?, masseditable = ? WHERE tablename = ? AND columnname = ?;', [3, 2, 2, 'vtiger_holidaysentitlement', 'days']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [1, 'vtiger_holidaysentitlement', 'ossemployeesid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [4, 'vtiger_crmentity', 'smownerid', getTabid('HolidaysEntitlement')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [3, 'vtiger_account', 'legal_form']);
        $adb->pquery('UPDATE vtiger_field SET sequence = ? WHERE tablename = ? AND columnname = ?;', [5, 'vtiger_leaddetails', 'industry']);
        $adb->pquery('UPDATE vtiger_field SET sequence = ? WHERE tablename = ? AND columnname = ?;', [8, 'vtiger_leaddetails', 'subindustry']);
        $adb->pquery('UPDATE vtiger_field SET sequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [9, 'vtiger_crmentity', 'was_read', getTabid('Leads')]);
        $adb->pquery('UPDATE vtiger_field SET sequence = ? WHERE tablename = ? AND columnname = ?;', [10, 'vtiger_leaddetails', 'leads_relation']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [8, 'vtiger_crmentity', 'smownerid', getTabid('Calendar')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [5, 'vtiger_activity', 'due_date', getTabid('Calendar')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ?, quickcreate = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [6, 2, 'vtiger_activity', 'process', getTabid('Calendar')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [4, 'vtiger_activity', 'link', getTabid('Calendar')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [1, 'vtiger_activity', 'subject', getTabid('Events')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [9, 'vtiger_crmentity', 'smownerid', getTabid('Events')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [3, 'vtiger_activity', 'date_start', getTabid('Events')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [5, 'vtiger_activity', 'due_date', getTabid('Events')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ?, quickcreate = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [6, 2, 'vtiger_activity', 'process', getTabid('Events')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [4, 'vtiger_activity', 'eventstatus', getTabid('Events')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [2, 'vtiger_activity', 'activitytype', getTabid('Events')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [8, 'vtiger_activity', 'link', getTabid('Events')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [7, 'vtiger_activity', 'allday', getTabid('Events')]);
        $adb->pquery('UPDATE vtiger_homestuff SET `visible` = ? WHERE `stufftype` = ? ;', [1, 'Tag Cloud']);
        $adb->pquery('UPDATE vtiger_field SET typeofdata = ? WHERE tablename = ? AND columnname = ?;', ['D~M', 'vtiger_projectmilestone', 'projectmilestonedate']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [2, 'vtiger_notes', 'filename', getTabid('Documents')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [5, 'vtiger_crmentity', 'smownerid', getTabid('Documents')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [4, 'vtiger_notes', 'filelocationtype', getTabid('Documents')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [3, 'vtiger_notes', 'folderid', getTabid('Documents')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [1, 'vtiger_modcomments', 'commentcontent', getTabid('ModComments')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [2, 'vtiger_crmentity', 'smownerid', getTabid('ModComments')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [3, 'vtiger_modcomments', 'related_to', getTabid('ModComments')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [7, 'vtiger_projecttask', 'projectid', getTabid('ProjectTask')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [8, 'vtiger_crmentity', 'smownerid', getTabid('ProjectTask')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [5, 'vtiger_projecttask', 'startdate', getTabid('ProjectTask')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [4, 'vtiger_projecttask', 'projecttaskstatus', getTabid('ProjectTask')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [1, 'vtiger_osspasswords', 'passwordname', getTabid('OSSPasswords')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [4, 'vtiger_osspasswords', 'username', getTabid('OSSPasswords')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [5, 'vtiger_osspasswords', 'password', getTabid('OSSPasswords')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [2, 'vtiger_osspasswords', 'link_adres', getTabid('OSSPasswords')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [3, 'vtiger_crmentity', 'smownerid', getTabid('OSSPasswords')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [4, 'vtiger_ossemployees', 'employee_status', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [3, 'vtiger_crmentity', 'smownerid', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [2, 'vtiger_ossemployees', 'last_name', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [17, 'vtiger_ossemployees', 'pesel', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [18, 'vtiger_ossemployees', 'id_card', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [5, 'vtiger_ossemployees', 'employee_education', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [6, 'vtiger_ossemployees', 'birth_date', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [19, 'vtiger_ossemployees', 'business_phone', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [16, 'vtiger_ossemployees', 'private_phone', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [21, 'vtiger_ossemployees', 'business_mail', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [20, 'vtiger_ossemployees', 'private_mail', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [22, 'vtiger_ossemployees', 'street', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [13, 'vtiger_ossemployees', 'code', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [9, 'vtiger_ossemployees', 'city', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [8, 'vtiger_ossemployees', 'state', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [10, 'vtiger_ossemployees', 'country', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [11, 'vtiger_ossemployees', 'ship_street', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [15, 'vtiger_ossemployees', 'ship_code', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [12, 'vtiger_ossemployees', 'ship_city', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [14, 'vtiger_ossemployees', 'ship_state', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ? AND tabid = ? ;', [7, 'vtiger_ossemployees', 'ship_country', getTabid('OSSEmployees')]);
        $adb->pquery('UPDATE vtiger_field SET defaultvalue = ?, summaryfield = ? WHERE tablename = ? AND columnname = ?;', ['PLL_WAITING_FOR_VERIFICATION', 1, 'vtiger_calculations', 'calculationsstatus']);
        $adb->pquery('UPDATE vtiger_field SET summaryfield = ? WHERE tablename = ? AND columnname = ?;', ['1', 'vtiger_calculations', 'name']);
        $adb->pquery('UPDATE vtiger_field SET summaryfield = ? WHERE tablename = ? AND columnname = ?;', ['1', 'vtiger_calculations', 'relatedid']);
        $adb->pquery('UPDATE vtiger_field SET summaryfield = ? WHERE tablename = ? AND columnname = ?;', ['1', 'vtiger_calculations', 'potentialid']);
        $adb->pquery('UPDATE vtiger_field SET summaryfield = ? WHERE tablename = ? AND columnname = ?;', ['1', 'vtiger_calculations', 'requirementcardsid']);
        $adb->pquery('UPDATE vtiger_field SET summaryfield = ?, displaytype = ? WHERE tablename = ? AND columnname = ?;', ['1', 1, 'vtiger_calculations', 'quotesenquiresid']);
        $adb->pquery('UPDATE vtiger_field SET quickcreatesequence = ? WHERE tablename = ? AND columnname = ?;', [3, 'vtiger_projecttask', 'estimated_work_time']);
        $widgets[] = array(53, 'Calculations', 'Summary', NULL, 1, 0, NULL, '[]');
        $widgets[] = array(54, 'Calculations', 'RelatedModule', '', 2, 1, NULL, '{"limit":"5","relatedmodule":"8","columns":"3","action":"1","filter":"-"}');
        foreach ($widgets as $widget) {
            if (self::checkModuleExists($widget[1])) {
                $result = $adb->pquery('SELECT * FROM vtiger_widgets WHERE tabid = ? AND `type` = ?', array(getTabid($widget[1]), $widget[2]));
                if (!$adb->num_rows($result)) {
                    $sql = "INSERT INTO vtiger_widgets (tabid, type, label, wcol, sequence, nomargin, data) VALUES (?, ?, ?, ?, ?, ?, ?);";
                    $adb->pquery($sql, array(getTabid($widget[1]), $widget[2], $widget[3], $widget[4], $widget[5], $widget[6], $widget[7]));
                }
            }
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_links` WHERE linktype = ? AND linklabel = ? AND tabid = ? ;", ['DASHBOARDWIDGET', 'Calculations', getTabid('Home')]);
        if ($adb->num_rows($result) == 0) {
            $instanceModule = Vtiger_Module::getInstance('Home');
            $instanceModule->addLink('DASHBOARDWIDGET', 'Calculations', 'index.php?module=Calculations&view=ShowWidget&name=Calculations');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_links` WHERE linktype = ? AND linklabel = ? AND tabid = ? ;", ['DASHBOARDWIDGET', 'PotentialsList', getTabid('Home')]);
        if ($adb->num_rows($result) == 0) {
            $instanceModule = Vtiger_Module::getInstance('Home');
            $instanceModule->addLink('DASHBOARDWIDGET', 'PotentialsList', 'index.php?module=Potentials&view=ShowWidget&name=PotentialsList');
        }
        // copy values from_portal in HelpDesk
        $result = $adb->query("SHOW COLUMNS FROM `vtiger_troubletickets` LIKE 'from_portal';");
        if ($adb->num_rows($result) == 0) {
            $adb->query("ALTER TABLE `vtiger_troubletickets` ADD COLUMN `from_portal` varchar(3) NULL after `ordertime` ;");
            $adb->query('UPDATE vtiger_troubletickets LEFT JOIN vtiger_ticketcf ON vtiger_troubletickets.ticketid = vtiger_ticketcf.ticketid SET vtiger_troubletickets.from_portal=vtiger_ticketcf.from_portal;');
            $adb->pquery('UPDATE `vtiger_field` SET tablename=? WHERE tablename = ? AND columnname = ? AND tabid = ?;', ['vtiger_troubletickets', 'vtiger_ticketcf', 'from_portal', getTabid('HelpDesk')]);
            $adb->pquery('alter table vtiger_ticketcf drop column from_portal');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_calendar_config` WHERE `type` = ? AND `name` = ? ;", ['info', 'notworkingdays']);
        if ($adb->num_rows($result) == 0) {
            $adb->query("insert  into `vtiger_calendar_config`(`type`,`name`,`label`,`value`) values ('info','notworkingdays ','LBL_NOTWORKING_DAYS',NULL);");
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_links` WHERE linklabel = ? AND linkicon = ? ; ", array('LBL_SHOW_ACCOUNT_HIERARCHY', 'icon-align-justify'));
        if ($adb->num_rows($result) == 0) {
            //$mods = Vtiger_Module::getInstance( "Accounts" );
            // $mods->deleteLink('DETAILVIEWBASIC', 'LBL_SHOW_ACCOUNT_HIERARCHY', 'index.php?module=Accounts&action=AccountHierarchy&accountid=$RECORD$');
            $adb->pquery("UPDATE `vtiger_links` SET `linkicon` = ? WHERE `linklabel`= ? ;", array('icon-align-justify', 'LBL_SHOW_ACCOUNT_HIERARCHY'));
            $adb->pquery("UPDATE `vtiger_links` SET `linkicon` = ? WHERE `linklabel`= ? ;", array('icon-file', 'LBL_ADD_NOTE'));
            $adb->pquery("UPDATE `vtiger_links` SET `linkicon` = 'icon-file'  WHERE `linklabel` = ?;", array('Add Note'));
            $adb->pquery("UPDATE `vtiger_links` SET `linkicon` = 'icon-tasks' WHERE `linklabel` = ?;", array('Add Project Task'));
            $adb->pquery("UPDATE `vtiger_links` SET `linkicon` = 'icon-user' WHERE `linklabel` = ?;", array('LBL_SHOW_EMPLOYEES_HIERARCHY'));
        }
        $result = $adb->query("SELECT * FROM `vtiger_backup_settings`;");
        if ($adb->num_rows($result) == 0) {
            $adb->query("insert  into `vtiger_backup_settings`(`type`,`param`,`value`) values ('folder','storage_folder','false');");
            $adb->query("insert  into `vtiger_backup_settings`(`type`,`param`,`value`) values ('folder','storage_folder','false');");
        }
        // change related list
        $update[] = array('tabid' => getTabid('OSSMailView'), 'related_tabid' => getTabid('Accounts'), 'change' => array('name' => 'get_accounts_mail'));
        $update[] = array('tabid' => getTabid('OSSMailView'), 'related_tabid' => getTabid('Contacts'), 'change' => array('name' => 'get_contacts_mail'));
        $update[] = array('tabid' => getTabid('OSSMailView'), 'related_tabid' => getTabid('Leads'), 'change' => array('name' => 'get_leads_mail'));
        $update[] = array('tabid' => getTabid('OSSMailView'), 'related_tabid' => getTabid('Potentials'), 'change' => array('name' => 'get_potentials_mail'));
        $update[] = array('tabid' => getTabid('OSSMailView'), 'related_tabid' => getTabid('HelpDesk'), 'change' => array('name' => 'get_helpdesk_mail'));
        $update[] = array('tabid' => getTabid('OSSMailView'), 'related_tabid' => getTabid('Project'), 'change' => array('name' => 'get_project_mail'));
        $update[] = array('tabid' => getTabid('OSSMailView'), 'related_tabid' => getTabid('ServiceContracts'), 'change' => array('name' => 'get_servicecontracts_mail'));
        $update[] = array('tabid' => getTabid('OSSMailView'), 'related_tabid' => getTabid('Campaigns'), 'change' => array('name' => 'get_campaigns_mail'));
        $update[] = array('tabid' => getTabid('Contacts'), 'related_tabid' => getTabid('OSSMailView'), 'change' => array('name' => 'get_emails'));
        $update[] = array('tabid' => getTabid('Leads'), 'related_tabid' => getTabid('OSSMailView'), 'change' => array('name' => 'get_emails'));
        $update[] = array('tabid' => getTabid('Accounts'), 'related_tabid' => getTabid('OSSMailView'), 'change' => array('name' => 'get_emails'));
        $update[] = array('tabid' => getTabid('Vendors'), 'related_tabid' => getTabid('OSSMailView'), 'change' => array('name' => 'get_emails'));
        $update[] = array('tabid' => getTabid('ServiceContracts'), 'related_tabid' => getTabid('OSSMailView'), 'change' => array('name' => 'get_emails', 'actions' => ''));
        $update[] = array('tabid' => getTabid('HelpDesk'), 'related_tabid' => getTabid('OSSMailView'), 'change' => array('name' => 'get_emails', 'actions' => ''));
        $update[] = array('tabid' => getTabid('Potentials'), 'related_tabid' => getTabid('OSSMailView'), 'change' => array('name' => 'get_emails', 'actions' => ''));
        $update[] = array('tabid' => getTabid('Campaigns'), 'related_tabid' => getTabid('OSSMailView'), 'change' => array('name' => 'get_emails', 'actions' => ''));
        $update[] = array('tabid' => getTabid('Project'), 'related_tabid' => getTabid('OSSMailView'), 'change' => array('name' => 'get_emails', 'actions' => ''));
        foreach ($update as $presents) {
            $sql1 = 'UPDATE `vtiger_relatedlists` SET ';
            foreach ($presents['change'] as $column => $value) {
                $sql = $sql1 . $column . ' = ? ';
                $sql .= 'WHERE `tabid` = ? AND `related_tabid` = ? ;';
                $adb->pquery($sql, array($value, $presents['tabid'], $presents['related_tabid']), true);
            }
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('OSSMailView'), getTabid('Vendors'), 'get_vendor_mail', 'Vendors'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Vendors');
            $target_Module = Vtiger_Module::getInstance('OSSMailView');
            $target_Module->setRelatedList($moduleInstance, 'Vendors', array('ADD,SELECT'), 'get_vendor_mail');
        }
        //mailview relation
        $module = 'OSSMailView';
        $sql = 'SELECT * FROM vtiger_crmentityrel WHERE module = ? OR relmodule = ?';
        $result1 = $adb->pquery($sql, [$module, $module]);
        for ($i = 0; $i < $adb->num_rows($result1); $i++) {
            $row = $adb->raw_query_result_rowdata($result1, $i);
            $id = $row['module'] == $module ? $row['relcrmid'] : $row['crmid'];
            $mailID = $row['module'] != $module ? $row['relcrmid'] : $row['crmid'];
            $sql = 'SELECT createdtime FROM vtiger_crmentity WHERE crmid = ?';
            $result2 = $adb->pquery($sql, [$mailID]);
            if ($adb->num_rows($result2) > 0) {
                $createdtime = $adb->query_result($result2, 0, 'createdtime');
                $adb->pquery('INSERT INTO vtiger_ossmailview_relation VALUES(?,?,?,?)', [$mailID, $id, $createdtime, 0]);
                $adb->pquery('DELETE FROM vtiger_crmentityrel WHERE crmid = ? AND relcrmid = ?; ', [$row['crmid'], $row['relcrmid']]);
            }
        }
        $adb->pquery('UPDATE `vtiger_ossmailview` LEFT JOIN `vtiger_crmentity` ON `vtiger_ossmailview`.`ossmailviewid` = `vtiger_crmentity`.`crmid`
		SET `vtiger_ossmailview`.`date` = vtiger_crmentity.`modifiedtime` WHERE `vtiger_ossmailview`.`date` IS NULL OR `vtiger_ossmailview`.`date` = ?', ['0000-00-00 00:00:00']);
        $result = $adb->pquery('SELECT * FROM `roundcube_system` WHERE name = ?;', array('roundcube-version'));
        if ($adb->num_rows($result) == 1) {
            $adb->pquery('UPDATE `roundcube_system` SET `value` = ? WHERE `name` = ?;', ['2015030800', 'roundcube-version']);
        } else {
            $adb->pquery('INSERT INTO `roundcube_system`(`name`,`value`) values (?,?);', ['2015030800', 'roundcube-version']);
        }
        //
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('Project'), getTabid('Contacts'), 'get_related_list', 'Contacts'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Contacts');
            $target_Module = Vtiger_Module::getInstance('Project');
            $target_Module->setRelatedList($moduleInstance, 'Contacts', array('ADD,SELECT'), 'get_related_list');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('Contacts'), getTabid('Project'), 'get_related_list', 'Project'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Project');
            $target_Module = Vtiger_Module::getInstance('Contacts');
            $target_Module->setRelatedList($moduleInstance, 'Project', array('ADD,SELECT'), 'get_related_list');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('Quotes'), getTabid('Contacts'), 'get_related_list', 'Contacts'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Contacts');
            $target_Module = Vtiger_Module::getInstance('Quotes');
            $target_Module->setRelatedList($moduleInstance, 'Contacts', array('ADD,SELECT'), 'get_related_list');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('Contacts'), getTabid('Quotes'), 'get_related_list', 'Quotes'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Quotes');
            $target_Module = Vtiger_Module::getInstance('Contacts');
            $target_Module->setRelatedList($moduleInstance, 'Quotes', array('ADD,SELECT'), 'get_related_list');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('Calculations'), getTabid('Contacts'), 'get_related_list', 'Contacts'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Contacts');
            $target_Module = Vtiger_Module::getInstance('Calculations');
            $target_Module->setRelatedList($moduleInstance, 'Contacts', array('ADD,SELECT'), 'get_related_list');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('Contacts'), getTabid('Calculations'), 'get_related_list', 'Calculations'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Calculations');
            $target_Module = Vtiger_Module::getInstance('Contacts');
            $target_Module->setRelatedList($moduleInstance, 'Calculations', array('ADD,SELECT'), 'get_related_list');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('QuotesEnquires'), getTabid('Contacts'), 'get_related_list', 'Contacts'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Contacts');
            $target_Module = Vtiger_Module::getInstance('QuotesEnquires');
            $target_Module->setRelatedList($moduleInstance, 'Contacts', array('ADD,SELECT'), 'get_related_list');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('Contacts'), getTabid('QuotesEnquires'), 'get_related_list', 'QuotesEnquires'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('QuotesEnquires');
            $target_Module = Vtiger_Module::getInstance('Contacts');
            $target_Module->setRelatedList($moduleInstance, 'QuotesEnquires', array('ADD,SELECT'), 'get_related_list');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('SalesOrder'), getTabid('Contacts'), 'get_related_list', 'Contacts'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Contacts');
            $target_Module = Vtiger_Module::getInstance('SalesOrder');
            $target_Module->setRelatedList($moduleInstance, 'Contacts', array('ADD,SELECT'), 'get_related_list');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('Contacts'), getTabid('SalesOrder'), 'get_related_list', 'SalesOrder'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('SalesOrder');
            $target_Module = Vtiger_Module::getInstance('Contacts');
            $target_Module->setRelatedList($moduleInstance, 'SalesOrder', array('ADD,SELECT'), 'get_related_list');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('PurchaseOrder'), getTabid('Contacts'), 'get_related_list', 'Contacts'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Contacts');
            $target_Module = Vtiger_Module::getInstance('PurchaseOrder');
            $target_Module->setRelatedList($moduleInstance, 'Contacts', array('ADD,SELECT'), 'get_related_list');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('Contacts'), getTabid('PurchaseOrder'), 'get_related_list', 'PurchaseOrder'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('PurchaseOrder');
            $target_Module = Vtiger_Module::getInstance('Contacts');
            $target_Module->setRelatedList($moduleInstance, 'PurchaseOrder', array('ADD,SELECT'), 'get_related_list');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('Invoice'), getTabid('Contacts'), 'get_related_list', 'Contacts'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Contacts');
            $target_Module = Vtiger_Module::getInstance('Invoice');
            $target_Module->setRelatedList($moduleInstance, 'Contacts', array('ADD,SELECT'), 'get_related_list');
        }
        $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ? AND name = ? AND label = ?;", array(getTabid('Contacts'), getTabid('Invoice'), 'get_related_list', 'Invoice'));
        if ($adb->num_rows($result) == 0) {
            $moduleInstance = Vtiger_Module::getInstance('Invoice');
            $target_Module = Vtiger_Module::getInstance('Contacts');
            $target_Module->setRelatedList($moduleInstance, 'Invoice', array('ADD,SELECT'), 'get_related_list');
        }
        $adb->pquery('UPDATE vtiger_field SET typeofdata = ? WHERE tablename = ? AND columnname = ?;', ['D~M', 'vtiger_calculations', 'date']);
        $result = $adb->pquery("SELECT * FROM `vtiger_dataaccess` WHERE module_name = ? AND `summary` = ?;", ['Events', 'Adding time period to status change']);
        if ($adb->num_rows($result) == 0) {
            $adb->pquery('insert  into `vtiger_dataaccess`(`module_name`,`summary`,`data`) values (?,?,?)', ['Events', 'Adding time period to status change', 'a:1:{i:0;a:3:{s:2:"an";s:25:"Vtiger!!show_quick_create";s:7:"modules";s:14:"OSSTimeControl";s:2:"cf";b:1;}}']);
            $recordId = $adb->getLastInsertID();
            $adb->pquery('insert  into `vtiger_dataaccess_cnd`(`dataaccessid`,`fieldname`,`comparator`,`val`,`required`,`field_type`) values (?,?,?,?,?,?);', [$recordId, 'eventstatus', 'has changed', 'Held', 1, 'picklist']);
        }
        $adb->pquery('UPDATE vtiger_links SET linkurl = ? WHERE linklabel = ?;', ['index.php?module=OSSTimeControl&view=ShowWidget&name=TimeControl', 'Employees Time Control']);
        $adb->pquery('DELETE FROM `vtiger_ws_entity` WHERE `name` = ? LIMIT 1;', ['OSSDocumentControl']);
        $adb->pquery("UPDATE vtiger_widgets SET data = ?  WHERE type = 'RelatedModule' AND label = 'ProjectTask';", ['{"limit":"5","relatedmodule":"' . getTabid('ProjectTask') . '","columns":"3","action":"1","filter":"-","checkbox_selected":"","checkbox":"-"}']);
        $adb->pquery("UPDATE vtiger_widgets SET data = ? WHERE type = 'RelatedModule' AND label = 'ProjectMilestone';", ['{"limit":"5","relatedmodule":"' . getTabid('ProjectMilestone') . '","columns":"3","action":"1","filter":"-","checkbox_selected":"","checkbox":"-"}']);
        $adb->query("UPDATE vtiger_widgets SET label = 'Documents' WHERE type = 'RelatedModule' AND tabid = '" . getTabid('Calculations') . "';");
        $log->debug("Exiting YetiForceUpdate::databaseData() method ...");
    }
Example #5
0
 public function databaseData()
 {
     global $log, $adb;
     $log->debug("Entering YetiForceUpdate::databaseData() method ...");
     $adb->query('UPDATE vtiger_eventhandlers SET handler_path = "include/events/VTEntityDelta.php" WHERE handler_path = "data/VTEntityDelta.php";');
     $result = $adb->query("SELECT * FROM `vtiger_ws_fieldtype` WHERE `uitype` = '120'");
     if ($adb->num_rows($result) == 0) {
         $adb->query("insert  into `vtiger_ws_fieldtype`(`uitype`,`fieldtype`) values ('120','sharedOwner');");
     }
     $result = $adb->query("SELECT * FROM `vtiger_ws_fieldtype` WHERE `uitype` = '301'");
     if ($adb->num_rows($result) == 0) {
         $adb->query("insert  into `vtiger_ws_fieldtype`(`uitype`,`fieldtype`) values ('301','modules');");
     }
     $result = $adb->query("SELECT * FROM `vtiger_ws_fieldtype` WHERE `uitype` = '302'");
     if ($adb->num_rows($result) == 0) {
         $adb->query("insert  into `vtiger_ws_fieldtype`(`uitype`,`fieldtype`) values ('302','tree');");
     }
     $result = $adb->query("SELECT `cvid` FROM `vtiger_customview` WHERE `viewname` = 'All' AND `entitytype` = 'Documents'; ");
     if ($adb->num_rows($result) == 1) {
         $cvId = $adb->query_result_raw($result, 0, 'cvid');
         $result = $adb->query("SELECT * FROM `vtiger_cvcolumnlist` WHERE `cvid` = '{$cvId}' AND `columnname` = 'vtiger_crmentity:modifiedtime:modifiedtime:Notes_Modified_Time:DT';");
         if ($adb->num_rows($result) == 1) {
             $adb->query("UPDATE vtiger_cvcolumnlist SET `columnname` = 'vtiger_notes:folderid:folderid:Documents_Folder_Name:V' WHERE `cvid` = '{$cvId}' AND `columnname` = 'vtiger_crmentity:modifiedtime:modifiedtime:Notes_Modified_Time:DT';");
         }
     }
     $result = $adb->query("SELECT * FROM `vtiger_settings_field` WHERE name = 'LBL_TREES_MANAGER'");
     if ($adb->num_rows($result) == 0) {
         $lastId = $adb->getUniqueID("vtiger_settings_field");
         $adb->query("insert  into `vtiger_settings_field`(`fieldid`,`blockid`,`name`,`iconpath`,`description`,`linkto`,`sequence`,`active`,`pinned`) values ({$lastId},2,'LBL_TREES_MANAGER',NULL,'LBL_TREES_MANAGER_DESCRIPTION','index.php?module=TreesManager&parent=Settings&view=List',15,0,0);");
     }
     $result = $adb->query("SELECT * FROM `vtiger_settings_field` WHERE name = 'LBL_MODTRACKER_SETTINGS'");
     if ($adb->num_rows($result) == 0) {
         $lastId = $adb->getUniqueID("vtiger_settings_field");
         $adb->query("insert  into `vtiger_settings_field`(`fieldid`,`blockid`,`name`,`iconpath`,`description`,`linkto`,`sequence`,`active`,`pinned`) values ({$lastId},2,'LBL_MODTRACKER_SETTINGS',NULL,'LBL_MODTRACKER_SETTINGS_DESCRIPTION','index.php?module=ModTracker&parent=Settings&view=List','16','0','0');");
     }
     $result = $adb->query("SELECT * FROM `vtiger_settings_field` WHERE name = 'LBL_ACTIVITY_TYPES'");
     if ($adb->num_rows($result) == 1) {
         $id = $adb->query_result_raw($result, 0, 'fieldid');
         $adb->query("UPDATE vtiger_settings_field SET `sequence` = '14' WHERE `fieldid` = {$id};");
     }
     $result = $adb->query("SELECT * FROM `vtiger_trees_templates`;");
     if ($adb->num_rows($result) == 0) {
         self::foldersToTree();
     }
     $result1 = $adb->query("SELECT workflow_id FROM `com_vtiger_workflows` WHERE summary = 'Workflow for Events when Send Notification is True'");
     $result2 = $adb->query("SELECT ossmailtemplatesid FROM `vtiger_ossmailtemplates` WHERE name = 'Send invitations'");
     $result3 = $adb->query("SELECT * FROM `com_vtiger_workflowtasks` WHERE `summary` = 'Send invitations'");
     if ($adb->num_rows($result1) == 1 && $adb->num_rows($result2) == 1 && $adb->num_rows($result3) == 1) {
         $workflow_id = $adb->query_result_raw($result1, 0, 'workflow_id');
         $ossmailtemplatesid = $adb->query_result_raw($result2, 0, 'ossmailtemplatesid');
         $task_id = $adb->query_result_raw($result3, 0, 'task_id');
         $taskRecordModel = Settings_Workflows_TaskRecord_Model::getInstance($task_id);
         $taskObject = $taskRecordModel->getTaskObject();
         if ($taskObject->template != $ossmailtemplatesid) {
             $taskObject->template = $ossmailtemplatesid;
             $taskRecordModel->save();
         }
     }
     $moduleInstance = Vtiger_Module::getInstance('CallHistory');
     $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ?;", array(getTabid('Contacts'), getTabid('CallHistory')));
     if ($adb->num_rows($result) == 0) {
         $targetModule = Vtiger_Module::getInstance('Contacts');
         $targetModule->setRelatedList($moduleInstance, 'CallHistory', array(), 'get_dependents_list');
     }
     $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ?;", array(getTabid('Accounts'), getTabid('CallHistory')));
     if ($adb->num_rows($result) == 0) {
         $targetModule = Vtiger_Module::getInstance('Accounts');
         $targetModule->setRelatedList($moduleInstance, 'CallHistory', array(), 'get_dependents_list');
     }
     $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ?;", array(getTabid('Leads'), getTabid('CallHistory')));
     if ($adb->num_rows($result) == 0) {
         $targetModule = Vtiger_Module::getInstance('Leads');
         $targetModule->setRelatedList($moduleInstance, 'CallHistory', array(), 'get_dependents_list');
     }
     $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ?;", array(getTabid('Vendors'), getTabid('CallHistory')));
     if ($adb->num_rows($result) == 0) {
         $targetModule = Vtiger_Module::getInstance('Vendors');
         $targetModule->setRelatedList($moduleInstance, 'CallHistory', array(), 'get_dependents_list');
     }
     $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ?;", array(getTabid('OSSEmployees'), getTabid('CallHistory')));
     if ($adb->num_rows($result) == 0) {
         $targetModule = Vtiger_Module::getInstance('OSSEmployees');
         $targetModule->setRelatedList($moduleInstance, 'CallHistory', array(), 'get_dependents_list');
     }
     $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ?;", array(getTabid('Potentials'), getTabid('CallHistory')));
     if ($adb->num_rows($result) == 0) {
         $targetModule = Vtiger_Module::getInstance('Potentials');
         $targetModule->setRelatedList($moduleInstance, 'CallHistory', array(), 'get_dependents_list');
     }
     $result = $adb->pquery("SELECT * FROM `vtiger_relatedlists` WHERE tabid = ? AND related_tabid = ?;", array(getTabid('HelpDesk'), getTabid('CallHistory')));
     if ($adb->num_rows($result) == 0) {
         $targetModule = Vtiger_Module::getInstance('HelpDesk');
         $targetModule->setRelatedList($moduleInstance, 'CallHistory', array(), 'get_dependents_list');
     }
     $result = $adb->pquery("SELECT * FROM `vtiger_links` WHERE linklabel = ?;", array('Employees Time Control'));
     if ($adb->num_rows($result) == 0) {
         $lastId = $adb->getUniqueID("vtiger_links");
         $adb->query("insert  into `vtiger_links`(`linkid`,`tabid`,`linktype`,`linklabel`,`linkurl`,`linkicon`,`sequence`,`handler_path`,`handler_class`,`handler`) values (" . $lastId . "," . getTabid('Home') . ",'DASHBOARDWIDGET','Employees Time Control','index.php?module=OSSEmployees&view=ShowWidget&name=TimeControl','',12,NULL,NULL,NULL);");
         $lastId = $adb->getUniqueID("vtiger_links");
         $adb->query("insert  into `vtiger_links`(`linkid`,`tabid`,`linktype`,`linklabel`,`linkurl`,`linkicon`,`sequence`,`handler_path`,`handler_class`,`handler`) values (" . $lastId . "," . getTabid('OSSEmployees') . ",'DASHBOARDWIDGET','Employees Time Control','index.php?module=OSSEmployees&view=ShowWidget&name=TimeControl','',1,NULL,NULL,NULL);");
     }
     /*
     $dbconfig = vglobal('dbconfig');
     $result = $adb->pquery("SELECT CONSTRAINT_NAME AS keyname FROM information_schema.TABLE_CONSTRAINTS WHERE TABLE_NAME = 'vtiger_module_dashboard_widgets' AND constraint_type = 'FOREIGN KEY' AND TABLE_SCHEMA = ?;",array($dbconfig['db_name']));
     if($adb->num_rows($result) > 0){
     	$adb->pquery("ALTER TABLE `vtiger_module_dashboard_widgets` DROP FOREIGN KEY ?;",array($adb->query_result_raw($result, 0, 'keyname')));
     }
     $adb->query("ALTER TABLE `vtiger_module_dashboard_widgets` ADD CONSTRAINT `vtiger_module_dashboard_widgets_ibfk_1` FOREIGN KEY (`templateid`) REFERENCES `vtiger_module_dashboard`(`id`) ON DELETE CASCADE;");
     */
     $adb->query("ALTER TABLE `vtiger_crmentity` CHANGE `was_read` `was_read` tinyint(1)   NULL DEFAULT 0 after `inheritsharing` ;");
     $adb->query("UPDATE vtiger_projecttype SET `projecttype` = 'PLL_INTERNAL' WHERE `projecttype` = 'administrative';");
     $adb->query("UPDATE vtiger_projecttype SET `projecttype` = 'PLL_EXTERNAL' WHERE `projecttype` = 'operative';");
     $adb->query("UPDATE vtiger_projecttype SET `projecttype` = 'PLL_COMMON' WHERE `projecttype` = 'other';");
     self::changeFieldOnTree();
     $log->debug("Exiting YetiForceUpdate::databaseData() method ...");
 }