Esempio n. 1
4
 function getPickListOptions($fieldName)
 {
     $default_charset = VTWS_PreserveGlobal::getGlobal('default_charset');
     $options = array();
     $sql = "select * from vtiger_picklist where name=?";
     $result = $this->pearDB->pquery($sql, array($fieldName));
     $numRows = $this->pearDB->num_rows($result);
     if ($numRows == 0) {
         $sql = "select * from vtiger_{$fieldName}";
         $result = $this->pearDB->pquery($sql, array());
         $numRows = $this->pearDB->num_rows($result);
         for ($i = 0; $i < $numRows; ++$i) {
             $elem = array();
             $picklistValue = $this->pearDB->query_result($result, $i, $fieldName);
             $picklistValue = html_entity_decode($picklistValue, ENT_QUOTES, $default_charset);
             $elem["label"] = getTranslatedString($picklistValue, $this->getMeta()->getTabName());
             $elem["value"] = $picklistValue;
             array_push($options, $elem);
         }
     } else {
         $details = getPickListValues($fieldName, $this->user->roleid);
         for ($i = 0; $i < sizeof($details); ++$i) {
             $elem = array();
             $picklistValue = html_entity_decode($details[$i], ENT_QUOTES, $default_charset);
             $elem["label"] = getTranslatedString($picklistValue, $this->getMeta()->getTabName());
             $elem["value"] = $picklistValue;
             array_push($options, $elem);
         }
     }
     return $options;
 }
Esempio n. 2
0
 public function fetchNameList($field, $result, $rel = null)
 {
     $referenceFieldInfoList = $this->queryGenerator->getReferenceFieldInfoList();
     $fieldName = $field->getFieldName();
     $rowCount = $this->db->num_rows($result);
     $idList = array();
     for ($i = 0; $i < $rowCount; $i++) {
         if ($rel == 1) {
             $modrel = getTabModuleName($field->getTabId());
             $colname = strtolower($modrel) . $field->getColumnName();
         } else {
             $colname = $field->getColumnName();
         }
         $id = $this->db->query_result($result, $i, $colname);
         if (!isset($this->nameList[$fieldName][$id])) {
             $idList[$id] = $id;
         }
     }
     $idList = array_keys($idList);
     if (count($idList) == 0) {
         return;
     }
     $moduleList = $referenceFieldInfoList[$fieldName];
     foreach ($moduleList as $module) {
         $meta = $this->queryGenerator->getMeta($module);
         if ($meta->isModuleEntity()) {
             if ($module == 'Users') {
                 $nameList = getOwnerNameList($idList);
             } else {
                 //TODO handle multiple module names overriding each other.
                 $nameList = getEntityName($module, $idList);
             }
         } else {
             $nameList = vtws_getActorEntityName($module, $idList);
         }
         $entityTypeList = array_intersect(array_keys($nameList), $idList);
         foreach ($entityTypeList as $id) {
             $this->typeList[$id] = $module;
         }
         if (empty($this->nameList[$fieldName])) {
             $this->nameList[$fieldName] = array();
         }
         foreach ($entityTypeList as $id) {
             $this->typeList[$id] = $module;
             $this->nameList[$fieldName][$id] = $nameList[$id];
         }
     }
 }
Esempio n. 3
0
 function getPickListOptions()
 {
     global $app_strings, $mod_strings, $log, $current_language;
     static $purified_plcache = array();
     $fieldName = $this->getFieldName();
     $default_charset = VTWS_PreserveGlobal::getGlobal('default_charset');
     $moduleName = getTabModuleName($this->getTabId());
     if ($moduleName == 'Events') {
         $moduleName = 'Calendar';
     }
     $temp_mod_strings = $moduleName != '' ? return_module_language($current_language, $moduleName) : $mod_strings;
     if (array_key_exists($moduleName . $fieldName, $purified_plcache)) {
         return $purified_plcache[$moduleName . $fieldName];
     }
     $options = array();
     $sql = "select * from vtiger_picklist where name=?";
     $result = $this->pearDB->pquery($sql, array($fieldName));
     $numRows = $this->pearDB->num_rows($result);
     if ($numRows == 0) {
         $sql = "select * from vtiger_{$fieldName}";
         $result = $this->pearDB->pquery($sql, array());
         $numRows = $this->pearDB->num_rows($result);
         for ($i = 0; $i < $numRows; ++$i) {
             $elem = array();
             $picklistValue = $this->pearDB->query_result($result, $i, $fieldName);
             $picklistValue = decode_html($picklistValue);
             $trans_str = $temp_mod_strings[$picklistValue] != '' ? $temp_mod_strings[$picklistValue] : ($app_strings[$picklistValue] != '' ? $app_strings[$picklistValue] : $picklistValue);
             while ($trans_str != preg_replace('/(.*) {.+}(.*)/', '$1$2', $trans_str)) {
                 $trans_str = preg_replace('/(.*) {.+}(.*)/', '$1$2', $trans_str);
             }
             $elem["label"] = $trans_str;
             $elem["value"] = $picklistValue;
             array_push($options, $elem);
         }
     } else {
         $user = VTWS_PreserveGlobal::getGlobal('current_user');
         $details = getPickListValues($fieldName, $user->roleid);
         for ($i = 0; $i < sizeof($details); ++$i) {
             $elem = array();
             $picklistValue = decode_html($details[$i]);
             $trans_str = $temp_mod_strings[$picklistValue] != '' ? $temp_mod_strings[$picklistValue] : ($app_strings[$picklistValue] != '' ? $app_strings[$picklistValue] : $picklistValue);
             while ($trans_str != preg_replace('/(.*) {.+}(.*)/', '$1$2', $trans_str)) {
                 $trans_str = preg_replace('/(.*) {.+}(.*)/', '$1$2', $trans_str);
             }
             $elem["label"] = $trans_str;
             $elem["value"] = $picklistValue;
             array_push($options, $elem);
         }
     }
     $purified_plcache[$moduleName . $fieldName] = $options;
     return $options;
 }
Esempio n. 4
0
 function deleteImage()
 {
     $sql1 = 'SELECT attachmentsid FROM vtiger_salesmanattachmentsrel WHERE smid = ?';
     $res1 = $this->db->pquery($sql1, array($this->id));
     if ($this->db->num_rows($res1) > 0) {
         $attachmentId = $this->db->query_result($res1, 0, 'attachmentsid');
         $sql2 = "DELETE FROM vtiger_crmentity WHERE crmid=? AND setype='Users Attachments'";
         $this->db->pquery($sql2, array($attachmentId));
         $sql3 = 'DELETE FROM vtiger_salesmanattachmentsrel WHERE smid=? AND attachmentsid=?';
         $this->db->pquery($sql3, array($this->id, $attachmentId));
         $sql2 = "UPDATE vtiger_users SET imagename='' WHERE id=?";
         $this->db->pquery($sql2, array($this->id));
         $sql4 = 'DELETE FROM vtiger_attachments WHERE attachmentsid=?';
         $this->db->pquery($sql4, array($attachmentId));
     }
 }
Esempio n. 5
0
 function getPickListOptions()
 {
     $fieldName = $this->getFieldName();
     $default_charset = VTWS_PreserveGlobal::getGlobal('default_charset');
     $options = array();
     $sql = "select * from vtiger_picklist where name=?";
     $result = $this->pearDB->pquery($sql, array($fieldName));
     $numRows = $this->pearDB->num_rows($result);
     if ($numRows == 0) {
         $sql = "select * from vtiger_{$fieldName}";
         $result = $this->pearDB->pquery($sql, array());
         $numRows = $this->pearDB->num_rows($result);
         for ($i = 0; $i < $numRows; ++$i) {
             $elem = array();
             $picklistValue = $this->pearDB->query_result($result, $i, $fieldName);
             $picklistValue = decode_html($picklistValue);
             $moduleName = getTabModuleName($this->getTabId());
             if ($moduleName == 'Events') {
                 $moduleName = 'Calendar';
             }
             $elem["label"] = getTranslatedString($picklistValue, $moduleName);
             $elem["value"] = $picklistValue;
             array_push($options, $elem);
         }
     } else {
         $user = VTWS_PreserveGlobal::getGlobal('current_user');
         $details = getPickListValues($fieldName, $user->roleid);
         for ($i = 0; $i < sizeof($details); ++$i) {
             $elem = array();
             $picklistValue = decode_html($details[$i]);
             $moduleName = getTabModuleName($this->getTabId());
             if ($moduleName == 'Events') {
                 $moduleName = 'Calendar';
             }
             $elem["label"] = getTranslatedString($picklistValue, $moduleName);
             $elem["value"] = $picklistValue;
             array_push($options, $elem);
         }
     }
     return $options;
 }
Esempio n. 6
0
 public function getReferenceList()
 {
     static $referenceList = array();
     if ($this->referenceList === null) {
         if (isset($referenceList[$this->getFieldId()])) {
             $this->referenceList = $referenceList[$this->getFieldId()];
             return $referenceList[$this->getFieldId()];
         }
         if (!isset(WebserviceField::$fieldTypeMapping[$this->getUIType()])) {
             $this->getFieldTypeFromUIType();
         }
         $fieldTypeData = WebserviceField::$fieldTypeMapping[$this->getUIType()];
         $referenceTypes = array();
         if ($this->getUIType() != $this->genericUIType) {
             $sql = "select * from vtiger_ws_referencetype where fieldtypeid=?";
             $params = array($fieldTypeData['fieldtypeid']);
         } else {
             $sql = 'select relmodule as type from vtiger_fieldmodulerel where fieldid=?';
             $params = array($this->getFieldId());
         }
         $result = $this->pearDB->pquery($sql, $params);
         $numRows = $this->pearDB->num_rows($result);
         for ($i = 0; $i < $numRows; ++$i) {
             array_push($referenceTypes, $this->pearDB->query_result($result, $i, "type"));
         }
         //to handle hardcoding done for Calendar module todo activities.
         if ($this->tabid == 9 && $this->fieldName == 'parent_id') {
             $referenceTypes[] = 'Invoice';
             $referenceTypes[] = 'Quotes';
             $referenceTypes[] = 'PurchaseOrder';
             $referenceTypes[] = 'SalesOrder';
             $referenceTypes[] = 'Campaigns';
         }
         $referenceList[$this->getFieldId()] = $referenceTypes;
         $this->referenceList = $referenceTypes;
         return $referenceTypes;
     }
     return $this->referenceList;
 }
Esempio n. 7
0
 function migrate($migrationInfo)
 {
     global $installationStrings;
     $completed = false;
     set_time_limit(0);
     //ADDED TO AVOID UNEXPECTED TIME OUT WHILE MIGRATING
     global $dbconfig;
     require $migrationInfo['root_directory'] . '/config.inc.php';
     $dbtype = $dbconfig['db_type'];
     $host = $dbconfig['db_server'] . $dbconfig['db_port'];
     $dbname = $dbconfig['db_name'];
     $username = $dbconfig['db_username'];
     $passwd = $dbconfig['db_password'];
     global $adb, $migrationlog;
     $adb = new PearDatabase($dbtype, $host, $dbname, $username, $passwd);
     $query = " ALTER DATABASE " . $adb->escapeDbName($dbname) . " DEFAULT CHARACTER SET utf8";
     $adb->query($query);
     $source_directory = $migrationInfo['source_directory'];
     if (file_exists($source_directory . 'user_privileges/CustomInvoiceNo.php')) {
         require_once $source_directory . 'user_privileges/CustomInvoiceNo.php';
     }
     $migrationlog =& LoggerManager::getLogger('MIGRATION');
     if (isset($migrationInfo['old_version'])) {
         $source_version = $migrationInfo['old_version'];
     }
     if (!isset($source_version) || empty($source_version)) {
         //If source version is not set then we cannot proceed
         echo "<br> " . $installationStrings['LBL_SOURCE_VERSION_NOT_SET'];
         exit;
     }
     $reach = 0;
     include $migrationInfo['root_directory'] . "/modules/Migration/versions.php";
     foreach ($versions as $version => $label) {
         if ($version == $source_version || $reach == 1) {
             $reach = 1;
             $temp[] = $version;
         }
     }
     $temp[] = $current_version;
     global $adb, $dbname;
     $_SESSION['adodb_current_object'] = $adb;
     @ini_set('zlib.output_compression', 0);
     @ini_set('output_buffering', 'off');
     ob_implicit_flush(true);
     echo '<table width="98%" border="1px" cellpadding="3" cellspacing="0" height="100%">';
     if (is_array($_SESSION['migration_info']['user_messages'])) {
         foreach ($_SESSION['migration_info']['user_messages'] as $infoMap) {
             echo "<tr><td>" . $infoMap['status'] . "</td><td>" . $infoMap['msg'] . "</td></tr>";
         }
     }
     echo "<tr><td colspan='2'><b>{$installationStrings['LBL_GOING_TO_APPLY_DB_CHANGES']}...</b></td></tr>";
     for ($patch_count = 0; $patch_count < count($temp); $patch_count++) {
         //Here we have to include all the files (all db differences for each release will be included)
         $filename = "modules/Migration/DBChanges/" . $temp[$patch_count] . "_to_" . $temp[$patch_count + 1] . ".php";
         $empty_tag = "<tr><td colspan='2'>&nbsp;</td></tr>";
         $start_tag = "<tr><td colspan='2'><b><font color='red'>&nbsp;";
         $end_tag = "</font></b></td></tr>";
         if (is_file($filename)) {
             echo $empty_tag . $start_tag . $temp[$patch_count] . " ==> " . $temp[$patch_count + 1] . " " . $installationStrings['LBL_DATABASE_CHANGES'] . " -- " . $installationStrings['LBL_STARTS'] . "." . $end_tag;
             include $filename;
             //include the file which contains the corresponding db changes
             echo $start_tag . $temp[$patch_count] . " ==> " . $temp[$patch_count + 1] . " " . $installationStrings['LBL_DATABASE_CHANGES'] . " -- " . $installationStrings['LBL_ENDS'] . "." . $end_tag;
         }
     }
     /* Install Vtlib Compliant Modules */
     Common_Install_Wizard_Utils::installMandatoryModules();
     Migration_Utils::installOptionalModules($migrationInfo['selected_optional_modules'], $migrationInfo['source_directory'], $migrationInfo['root_directory']);
     Migration_utils::copyLanguageFiles($migrationInfo['source_directory'], $migrationInfo['root_directory']);
     //Here we have to update the version in table. so that when we do migration next time we will get the version
     $res = $adb->query('SELECT * FROM vtiger_version');
     global $vtiger_current_version;
     require $migrationInfo['root_directory'] . '/vtigerversion.php';
     if ($adb->num_rows($res)) {
         $res = ExecuteQuery("UPDATE vtiger_version SET old_version='{$versions[$source_version]}',current_version='{$vtiger_current_version}'");
         $completed = true;
     } else {
         ExecuteQuery("INSERT INTO vtiger_version (id, old_version, current_version) values (" . $adb->getUniqueID('vtiger_version') . ", '{$versions[$source_version]}', '{$vtiger_current_version}');");
         $completed = true;
     }
     echo '</table><br><br>';
     create_tab_data_file();
     create_parenttab_data_file();
     return $completed;
 }
    function getListViewEntries($focus, $module, $result, $navigationInfo, $skipActions = false)
    {
        require 'user_privileges/user_privileges_' . $this->user->id . '.php';
        global $listview_max_textlength, $theme, $default_charset, $current_user, $currentModule;
        $fields = $this->queryGenerator->getFields();
        $whereFields = $this->queryGenerator->getWhereFields();
        $meta = $this->queryGenerator->getMeta($this->queryGenerator->getModule());
        $moduleFields = $meta->getModuleFields();
        $accessibleFieldList = array_keys($moduleFields);
        if ($this->queryGenerator->getReferenceFieldInfoList()) {
            $accessibleFieldList = array_merge($this->queryGenerator->getReferenceFieldNameList(), $accessibleFieldList);
        }
        $listViewFields = array_intersect($fields, $accessibleFieldList);
        $referenceFieldList = $this->queryGenerator->getReferenceFieldList();
        foreach ($referenceFieldList as $fieldName) {
            if (in_array($fieldName, $listViewFields)) {
                $field = $moduleFields[$fieldName];
                $this->fetchNameList($field, $result);
            }
        }
        $db = PearDatabase::getInstance();
        $rowCount = $db->num_rows($result);
        $listviewcolumns = $db->getFieldsArray($result);
        $ownerFieldList = $this->queryGenerator->getOwnerFieldList();
        foreach ($ownerFieldList as $fieldName) {
            if (in_array($fieldName, $listViewFields)) {
                if (!empty($moduleFields[$fieldName])) {
                    $field = $moduleFields[$fieldName];
                } else {
                    $field = $this->queryGenerator->getReferenceField($fieldName, false);
                    if (is_null($field)) {
                        continue;
                    }
                }
                $fldcolname = $field->getColumnName();
                $idList = array();
                for ($i = 0; $i < $rowCount; $i++) {
                    $id = $this->db->query_result($result, $i, $fldcolname);
                    if (!isset($this->ownerNameList[$fieldName][$id])) {
                        $idList[] = $id;
                    }
                }
                if (count($idList) > 0) {
                    if (!isset($this->ownerNameList[$fieldName]) or !is_array($this->ownerNameList[$fieldName])) {
                        $this->ownerNameList[$fieldName] = getOwnerNameList($idList);
                    } else {
                        $newOwnerList = getOwnerNameList($idList);
                        $this->ownerNameList[$fieldName] = $this->ownerNameList[$fieldName] + $newOwnerList;
                    }
                }
            }
        }
        foreach ($listViewFields as $fieldName) {
            if (!empty($moduleFields[$fieldName])) {
                $field = $moduleFields[$fieldName];
            } else {
                $field = $this->queryGenerator->getReferenceField($fieldName, false);
                if (is_null($field)) {
                    continue;
                }
            }
            if (!$is_admin && ($field->getFieldDataType() == 'picklist' || $field->getFieldDataType() == 'multipicklist')) {
                $this->setupAccessiblePicklistValueList($fieldName);
            }
            $idList = array();
            if ($fieldName != 'assigned_user_id' && strstr($fieldName, ".assigned_user_id")) {
                $modrel = getTabModuleName($field->getTabId());
                $fldcolname = 'smowner' . strtolower($modrel);
                $j = $rowCount * $k;
                $k++;
                for ($i = 0; $i < $rowCount; $i++) {
                    $id = $this->db->query_result($result, $i, $fldcolname);
                    if (!isset($this->ownerNameListrel[$fieldName][$id])) {
                        $idList[$j] = $id;
                        $j++;
                    }
                }
            } else {
                if (getTabid($currentModule) != $field->getTabId() && $field->getFieldDataType() == 'reference') {
                    $this->fetchNameList($field, $result, 1);
                }
            }
            if (count($idList) > 0) {
                if (!isset($this->ownerNameListrel[$fieldName]) or !is_array($this->ownerNameListrel[$fieldName])) {
                    $this->ownerNameListrel[$fieldName] = getOwnerNameList($idList);
                } else {
                    $newOwnerList = getOwnerNameList($idList);
                    $this->ownerNameListrel[$fieldName] = $this->ownerNameListrel[$fieldName] + $newOwnerList;
                }
            }
        }
        $useAsterisk = get_use_asterisk($this->user->id);
        $data = array();
        for ($i = 0; $i < $rowCount; ++$i) {
            //Getting the recordId
            if ($module != 'Users') {
                $baseTable = $meta->getEntityBaseTable();
                $moduleTableIndexList = $meta->getEntityTableIndexList();
                $baseTableIndex = $moduleTableIndexList[$baseTable];
                $recordId = $db->query_result($result, $i, $baseTableIndex);
                $ownerId = $db->query_result($result, $i, "smownerid");
            } else {
                $recordId = $db->query_result($result, $i, "id");
            }
            $row = array();
            foreach ($listViewFields as $fieldName) {
                if (!empty($moduleFields[$fieldName])) {
                    $field = $moduleFields[$fieldName];
                } else {
                    $field = $this->queryGenerator->getReferenceField($fieldName, false);
                    if (is_null($field)) {
                        continue;
                    }
                }
                $uitype = $field->getUIType();
                if ($fieldName != 'assigned_user_id' && strstr($fieldName, ".assigned_user_id")) {
                    $modrel = getTabModuleName($field->getTabId());
                    $rawValue = $this->db->query_result($result, $i, "smowner" . strtolower($modrel));
                } else {
                    if (getTabid($currentModule) != $field->getTabId()) {
                        $modrel = getTabModuleName($field->getTabId());
                        $relfieldname = strtolower($modrel) . $field->getColumnName();
                        if (in_array($relfieldname, $listviewcolumns)) {
                            $rawValue = $this->db->query_result($result, $i, $relfieldname);
                        } else {
                            $rawValue = $this->db->query_result($result, $i, $field->getColumnName());
                        }
                    } else {
                        $rawValue = $this->db->query_result($result, $i, $field->getColumnName());
                    }
                }
                if ($module == 'Calendar') {
                    $activityType = $this->db->query_result($result, $i, 'activitytype');
                }
                if ($uitype != 8) {
                    $value = html_entity_decode($rawValue, ENT_QUOTES, $default_charset);
                } else {
                    $value = $rawValue;
                }
                if ($module == 'Documents' && $fieldName == 'filename') {
                    $downloadtype = $db->query_result($result, $i, 'filelocationtype');
                    if ($downloadtype == 'I') {
                        $ext = substr($value, strrpos($value, ".") + 1);
                        $ext = strtolower($ext);
                        if ($value != '') {
                            if ($ext == 'bin' || $ext == 'exe' || $ext == 'rpm') {
                                $fileicon = "<img src='" . vtiger_imageurl('fExeBin.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                            } elseif ($ext == 'jpg' || $ext == 'gif' || $ext == 'bmp') {
                                $fileicon = "<img src='" . vtiger_imageurl('fbImageFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                            } elseif ($ext == 'txt' || $ext == 'doc' || $ext == 'xls') {
                                $fileicon = "<img src='" . vtiger_imageurl('fbTextFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                            } elseif ($ext == 'zip' || $ext == 'gz' || $ext == 'rar') {
                                $fileicon = "<img src='" . vtiger_imageurl('fbZipFile.gif', $theme) . "' hspace='3' align='absmiddle'\tborder='0'>";
                            } else {
                                $fileicon = "<img src='" . vtiger_imageurl('fbUnknownFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                            }
                        }
                    } elseif ($downloadtype == 'E') {
                        if (trim($value) != '') {
                            $fileicon = "<img src='" . vtiger_imageurl('fbLink.gif', $theme) . "' alt='" . getTranslatedString('LBL_EXTERNAL_LNK', $module) . "' title='" . getTranslatedString('LBL_EXTERNAL_LNK', $module) . "' hspace='3' align='absmiddle' border='0'>";
                        } else {
                            $value = '--';
                            $fileicon = '';
                        }
                    } else {
                        $value = ' --';
                        $fileicon = '';
                    }
                    $fileName = $db->query_result($result, $i, 'filename');
                    $downloadType = $db->query_result($result, $i, 'filelocationtype');
                    $status = $db->query_result($result, $i, 'filestatus');
                    $fileIdQuery = "select attachmentsid from vtiger_seattachmentsrel where crmid=?";
                    $fileIdRes = $db->pquery($fileIdQuery, array($recordId));
                    $fileId = $db->query_result($fileIdRes, 0, 'attachmentsid');
                    if ($fileName != '' && $status == 1) {
                        if ($downloadType == 'I') {
                            $value = "<a href='index.php?module=uploads&action=downloadfile&" . "entityid={$recordId}&fileid={$fileId}' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "' onclick='javascript:dldCntIncrease({$recordId});'>" . textlength_check($value) . "</a>";
                        } elseif ($downloadType == 'E') {
                            $value = "<a target='_blank' href='{$fileName}' onclick='javascript:" . "dldCntIncrease({$recordId});' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "'>" . textlength_check($value) . "</a>";
                        } else {
                            $value = ' --';
                        }
                    }
                    $value = $fileicon . $value;
                } elseif ($module == 'Documents' && $fieldName == 'filesize') {
                    $downloadType = $db->query_result($result, $i, 'filelocationtype');
                    if ($downloadType == 'I') {
                        $filesize = $value;
                        if ($filesize < 1024) {
                            $value = $filesize . ' B';
                        } elseif ($filesize > 1024 && $filesize < 1048576) {
                            $value = round($filesize / 1024, 2) . ' KB';
                        } else {
                            if ($filesize > 1048576) {
                                $value = round($filesize / (1024 * 1024), 2) . ' MB';
                            }
                        }
                    } else {
                        $value = ' --';
                    }
                } elseif ($module == 'Documents' && $fieldName == 'filestatus') {
                    if ($value == 1) {
                        $value = getTranslatedString('yes', $module);
                    } elseif ($value == 0) {
                        $value = getTranslatedString('no', $module);
                    } else {
                        $value = '--';
                    }
                } elseif ($module == 'Documents' && $fieldName == 'filetype') {
                    $downloadType = $db->query_result($result, $i, 'filelocationtype');
                    if ($downloadType == 'E' || $downloadType != 'I') {
                        $value = '--';
                    }
                } elseif ($field->getUIType() == '27') {
                    if ($value == 'I') {
                        $value = getTranslatedString('LBL_INTERNAL', $module);
                    } elseif ($value == 'E') {
                        $value = getTranslatedString('LBL_EXTERNAL', $module);
                    } else {
                        $value = ' --';
                    }
                } elseif ($field->getFieldDataType() == 'picklist') {
                    if ($value != '' && !$is_admin && $this->picklistRoleMap[$fieldName] && !in_array($value, $this->picklistValueMap[$fieldName])) {
                        $value = "<font color='red'>" . getTranslatedString('LBL_NOT_ACCESSIBLE', $module) . "</font>";
                    } else {
                        $value = getTranslatedString($value, $module);
                        $value = textlength_check($value);
                    }
                } elseif ($field->getFieldDataType() == 'date' || $field->getFieldDataType() == 'datetime') {
                    if ($value != '' && $value != '0000-00-00') {
                        $date = new DateTimeField($value);
                        $value = $date->getDisplayDate();
                        if ($field->getFieldDataType() == 'datetime') {
                            $value .= ' ' . $date->getDisplayTime();
                        }
                    } elseif ($value == '0000-00-00') {
                        $value = '';
                    }
                } elseif ($field->getFieldDataType() == 'currency') {
                    if ($value != '') {
                        if ($field->getUIType() == 72) {
                            if ($fieldName == 'unit_price') {
                                $currencyId = getProductBaseCurrency($recordId, $module);
                                $cursym_convrate = getCurrencySymbolandCRate($currencyId);
                                $currencySymbol = $cursym_convrate['symbol'];
                            } else {
                                $currencyInfo = getInventoryCurrencyInfo($module, $recordId);
                                $currencySymbol = $currencyInfo['currency_symbol'];
                            }
                            $value = number_format($value, 2, '.', '');
                            $currencyValue = CurrencyField::convertToUserFormat($value, null, true);
                            $value = CurrencyField::appendCurrencySymbol($currencyValue, $currencySymbol);
                        } else {
                            //changes made to remove vtiger_currency symbol infront of each
                            //vtiger_potential amount
                            if ($value != 0) {
                                $value = CurrencyField::convertToUserFormat($value);
                            }
                        }
                    }
                } elseif ($field->getFieldDataType() == 'url') {
                    $matchPattern = "^[\\w]+:\\/\\/^";
                    preg_match($matchPattern, $rawValue, $matches);
                    if (!empty($matches[0])) {
                        $value = '<a href="' . $rawValue . '" target="_blank">' . textlength_check($value) . '</a>';
                    } else {
                        $value = '<a href="http://' . $rawValue . '" target="_blank">' . textlength_check($value) . '</a>';
                    }
                } elseif ($field->getFieldDataType() == 'email') {
                    if ($_SESSION['internal_mailer'] == 1) {
                        //check added for email link in user detailview
                        $fieldId = $field->getFieldId();
                        $value = "<a href=\"javascript:InternalMailer({$recordId},{$fieldId}," . "'{$fieldName}','{$module}','record_id');\">" . textlength_check($value) . "</a>";
                    } else {
                        $value = '<a href="mailto:' . $rawValue . '">' . textlength_check($value) . '</a>';
                    }
                } elseif ($field->getFieldDataType() == 'boolean') {
                    if ($value == 1) {
                        $value = getTranslatedString('yes', $module);
                    } elseif ($value == 0) {
                        $value = getTranslatedString('no', $module);
                    } else {
                        $value = '--';
                    }
                } elseif ($field->getUIType() == 98) {
                    $value = '<a href="index.php?action=RoleDetailView&module=Settings&parenttab=' . 'Settings&roleid=' . $value . '">' . textlength_check(getRoleName($value)) . '</a>';
                } elseif ($field->getUIType() == 69) {
                    if ($module == 'Products') {
                        $queryPrdt = 'SELECT vtiger_attachments.path,vtiger_attachments.attachmentsid,vtiger_attachments.`name`
							FROM vtiger_attachments
							INNER JOIN vtiger_seattachmentsrel ON vtiger_attachments.attachmentsid = vtiger_seattachmentsrel.attachmentsid
							INNER JOIN vtiger_products ON vtiger_seattachmentsrel.crmid = vtiger_products.productid
							where vtiger_seattachmentsrel.crmid=?';
                        $resultprdt = $this->db->pquery($queryPrdt, array($recordId));
                        if ($resultprdt and $this->db->num_rows($resultprdt) > 0) {
                            $imgpath = $this->db->query_result($resultprdt, 0, 'path');
                            $attid = $this->db->query_result($resultprdt, 0, 'attachmentsid');
                            $imgfilename = $this->db->query_result($resultprdt, 0, 'name');
                            $value = "<div style='text-align:center;width:100%;'><img src='./" . $imgpath . $attid . '_' . $imgfilename . "' height='50'></div>";
                        } else {
                            $value = '';
                        }
                    } else {
                        if ($module == 'Contacts') {
                            $imageattachment = 'Image';
                        } else {
                            $imageattachment = 'Attachment';
                        }
                        //$imgpath = getModuleFileStoragePath('Contacts').$col_fields[$fieldname];
                        $sql = "select vtiger_attachments.*,vtiger_crmentity.setype\n\t\t\t\t\t\t from vtiger_attachments\n\t\t\t\t\t\t inner join vtiger_seattachmentsrel on vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid\n\t\t\t\t\t\t inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_attachments.attachmentsid\n\t\t\t\t\t\t where vtiger_crmentity.setype='{$module} {$imageattachment}'\n\t\t\t\t\t\t  and vtiger_attachments.name = ?\n\t\t\t\t\t\t  and vtiger_seattachmentsrel.crmid=?";
                        $image_res = $this->db->pquery($sql, array(str_replace(' ', '_', $value), $recordId));
                        $image_id = $this->db->query_result($image_res, 0, 'attachmentsid');
                        $image_path = $this->db->query_result($image_res, 0, 'path');
                        $image_name = urlencode(decode_html($this->db->query_result($image_res, 0, 'name')));
                        $imgpath = $image_path . $image_id . "_" . $image_name;
                        if ($image_name != '') {
                            $ftype = $this->db->query_result($image_res, 0, 'type');
                            $isimage = stripos($ftype, 'image') !== false;
                            if ($isimage) {
                                $imgtxt = getTranslatedString('SINGLE_' . $module, $module) . ' ' . getTranslatedString('Image');
                                $value = '<div style="width:100%;text-align:center;"><img src="' . $imgpath . '" alt="' . $imgtxt . '" title= "' . $imgtxt . '" style="max-width: 50px;"></div>';
                            } else {
                                $imgtxt = getTranslatedString('SINGLE_' . $module, $module) . ' ' . getTranslatedString('SINGLE_Documents');
                                $value = '<a href="' . $imgpath . '" alt="' . $imgtxt . '" title= "' . $imgtxt . '">' . $image_name . '</a>';
                            }
                        } else {
                            $value = '';
                        }
                    }
                } elseif ($field->getFieldDataType() == 'multipicklist') {
                    $value = $value != "" ? str_replace(' |##| ', ', ', $value) : "";
                    if (!$is_admin && $value != '') {
                        $valueArray = $rawValue != "" ? explode(' |##| ', $rawValue) : array();
                        $notaccess = '<font color="red">' . getTranslatedString('LBL_NOT_ACCESSIBLE', $module) . "</font>";
                        $tmp = '';
                        $tmpArray = array();
                        foreach ($valueArray as $index => $val) {
                            if (!$listview_max_textlength || !(strlen(preg_replace("/(<\\/?)(\\w+)([^>]*>)/i", "", $tmp)) > $listview_max_textlength)) {
                                if (!$is_admin && $this->picklistRoleMap[$fieldName] && !in_array(trim(decode_html($val)), $this->picklistValueMap[$fieldName])) {
                                    $tmpArray[] = $notaccess;
                                    $tmp .= ', ' . $notaccess;
                                } else {
                                    $tmpArray[] = $val;
                                    $tmp .= ', ' . $val;
                                }
                            } else {
                                $tmpArray[] = '...';
                                $tmp .= '...';
                            }
                        }
                        $value = implode(', ', $tmpArray);
                        $value = textlength_check($value);
                    }
                } elseif ($field->getUIType() == 1024) {
                    $content = array();
                    if ($value != '') {
                        $arr_evo_actions = explode(' |##| ', $value);
                        for ($fvalues = 0; $fvalues < sizeof($arr_evo_actions); $fvalues++) {
                            $roleid = $arr_evo_actions[$fvalues];
                            $rolename = getRoleName($roleid);
                            $content[$fvalues] = $rolename;
                        }
                    }
                    $value = textlength_check(implode(', ', $content));
                } elseif ($field->getFieldDataType() == 'skype') {
                    $value = $value != "" ? "<a href='skype:{$value}?call'>" . textlength_check($value) . "</a>" : "";
                } elseif ($field->getFieldDataType() == 'phone') {
                    if ($useAsterisk == 'true') {
                        $value = "<a href='javascript:;' onclick='startCall(&quot;{$value}&quot;, " . "&quot;{$recordId}&quot;)'>" . textlength_check($value) . "</a>";
                    } else {
                        $value = textlength_check($value);
                    }
                } elseif ($field->getFieldDataType() == 'reference') {
                    $referenceFieldInfoList = $this->queryGenerator->getReferenceFieldInfoList();
                    if (getTabid($currentModule) != $field->getTabId()) {
                        $modrel = getTabModuleName($field->getTabId());
                        $fieldName = str_replace($modrel . '.', "", $fieldName);
                    }
                    $moduleList = $referenceFieldInfoList[$fieldName];
                    if (count($moduleList) == 1) {
                        $parentModule = $moduleList[0];
                    } else {
                        $parentModule = $this->typeList[$value];
                    }
                    if (!empty($value) && !empty($this->nameList[$fieldName]) && !empty($parentModule)) {
                        $parentMeta = $this->queryGenerator->getMeta($parentModule);
                        $value = textlength_check($this->nameList[$fieldName][$value]);
                        if ($parentMeta->isModuleEntity() && $parentModule != "Users") {
                            $value = "<a href='index.php?module={$parentModule}&action=DetailView&" . "record={$rawValue}' title='" . getTranslatedString($parentModule, $parentModule) . "'>{$value}</a>";
                        }
                    } else {
                        $value = '--';
                    }
                } elseif ($field->getFieldDataType() == 'owner') {
                    if ($fieldName != 'assigned_user_id' && strstr($fieldName, ".assigned_user_id")) {
                        $value = textlength_check($this->ownerNameListrel[$fieldName][$value]);
                    } else {
                        $value = textlength_check($this->ownerNameList[$fieldName][$value]);
                    }
                } elseif ($field->getUIType() == 25) {
                    //TODO clean request object reference.
                    $contactId = $_REQUEST['record'];
                    $emailId = $this->db->query_result($result, $i, "activityid");
                    $result1 = $this->db->pquery("SELECT access_count FROM vtiger_email_track WHERE " . "crmid=? AND mailid=?", array($contactId, $emailId));
                    $value = $this->db->query_result($result1, 0, "access_count");
                    if (!$value) {
                        $value = 0;
                    }
                } elseif ($field->getUIType() == 8) {
                    if (!empty($value)) {
                        $temp_val = html_entity_decode($value, ENT_QUOTES, $default_charset);
                        $json = new Zend_Json();
                        $value = vt_suppressHTMLTags(implode(',', $json->decode($temp_val)));
                    }
                } elseif (in_array($uitype, array(7, 9, 90))) {
                    $value = "<span align='right'>" . textlength_check($value) . "</div>";
                } elseif ($field->getUIType() == 55) {
                    $value = getTranslatedString($value, $currentModule);
                } else {
                    $value = textlength_check($value);
                }
                $parenttab = getParentTab();
                $nameFields = $this->queryGenerator->getModuleNameFields($module);
                $nameFieldList = explode(',', $nameFields);
                if (in_array($fieldName, $nameFieldList) && $module != 'Emails') {
                    $value = "<a href='index.php?module={$module}&parenttab={$parenttab}&action=DetailView&record=" . "{$recordId}' title='" . getTranslatedString($module, $module) . "'>{$value}</a>";
                } elseif ($fieldName == $focus->list_link_field && $module != 'Emails') {
                    $value = "<a href='index.php?module={$module}&parenttab={$parenttab}&action=DetailView&record=" . "{$recordId}' title='" . getTranslatedString($module, $module) . "'>{$value}</a>";
                }
                // vtlib customization: For listview javascript triggers
                $value = "{$value} <span type='vtlib_metainfo' vtrecordid='{$recordId}' vtfieldname=" . "'{$fieldName}' vtmodule='{$module}' style='display:none;'></span>";
                // END
                $row[] = $value;
            }
            //Added for Actions ie., edit and delete links in listview
            $actionLinkInfo = "";
            if (isPermitted($module, "EditView", "") == 'yes') {
                $edit_link = $this->getListViewEditLink($module, $recordId);
                if (isset($navigationInfo['start']) && $navigationInfo['start'] > 1 && $module != 'Emails') {
                    $actionLinkInfo .= "<a href=\"{$edit_link}&start=" . $navigationInfo['start'] . "\">" . getTranslatedString("LNK_EDIT", $module) . "</a> ";
                } else {
                    $actionLinkInfo .= "<a href=\"{$edit_link}\">" . getTranslatedString("LNK_EDIT", $module) . "</a> ";
                }
            }
            if (isPermitted($module, "Delete", "") == 'yes') {
                $del_link = $this->getListViewDeleteLink($module, $recordId);
                if ($actionLinkInfo != "" && $del_link != "") {
                    $actionLinkInfo .= ' | ';
                }
                if ($del_link != "") {
                    $actionLinkInfo .= "<a href='javascript:confirmdelete(\"" . addslashes(urlencode($del_link)) . "\")'>" . getTranslatedString("LNK_DELETE", $module) . "</a>";
                }
            }
            // Record Change Notification
            if (method_exists($focus, 'isViewed') && PerformancePrefs::getBoolean('LISTVIEW_RECORD_CHANGE_INDICATOR', true)) {
                if (!$focus->isViewed($recordId)) {
                    $actionLinkInfo .= " | <img src='" . vtiger_imageurl('important1.gif', $theme) . "' border=0>";
                }
            }
            // END
            if ($actionLinkInfo != "" && !$skipActions) {
                $row[] = $actionLinkInfo;
            }
            list($row, $unused, $unused2) = cbEventHandler::do_filter('corebos.filter.listview.render', array($row, $this->db->query_result_rowdata($result, $i), $recordId));
            $data[$recordId] = $row;
        }
        return $data;
    }
Esempio n. 9
0
 function process()
 {
     set_time_limit(0);
     //ADDED TO AVOID UNEXPECTED TIME OUT WHILE MIGRATING
     $returnValue = vtiger_DatabaseMigration::initMigration();
     if ($returnValue !== true) {
         echo $returnValue;
         return false;
     }
     global $dbconfig;
     require dirname(__FILE__) . '/config.inc.php';
     $dbtype = $dbconfig['db_type'];
     $host = $dbconfig['db_server'] . $dbconfig['db_port'];
     $dbname = $dbconfig['db_name'];
     $username = $dbconfig['db_username'];
     $passwd = $dbconfig['db_password'];
     global $adb, $migrationlog;
     $adb = new PearDatabase($dbtype, $host, $dbname, $username, $passwd);
     // Why do we do this here? We shouldn't alter here if its not in UTF8.
     $query = " ALTER DATABASE " . $dbname . " DEFAULT CHARACTER SET utf8";
     $adb->query($query);
     $source_directory = $_SESSION['migration_info']['source_directory'];
     if (file_exists($source_directory . 'user_privileges/CustomInvoiceNo.php')) {
         require_once $source_directory . 'user_privileges/CustomInvoiceNo.php';
     }
     $versions_non_utf8 = array("50", "501", "502", "503rc2", "503", "504rc");
     $php_max_execution_time = 0;
     $migrationlog =& LoggerManager::getLogger('MIGRATION');
     if (isset($_SESSION['migration_info']['old_version'])) {
         $source_version = $_SESSION['migration_info']['old_version'];
     }
     if (!isset($source_version) || empty($source_version)) {
         //If source version is not set then we cannot proceed
         echo "<br> Source Version is not set. Please check vtigerversion.php and contiune the Patch Process";
         exit;
     }
     $reach = 0;
     include dirname(__FILE__) . "/modules/Migration/versions.php";
     foreach ($versions as $version => $label) {
         if ($version == $source_version || $reach == 1) {
             $reach = 1;
             $temp[] = $version;
         }
     }
     $temp[] = $current_version;
     global $adb, $dbname;
     $_SESSION['adodb_current_object'] = $adb;
     @ini_set('zlib.output_compression', 0);
     @ini_set('output_buffering', 'off');
     ob_implicit_flush(true);
     echo '<table width="98%" border="1px" cellpadding="3" cellspacing="0" height="100%">';
     echo "<tr><td colspan='2'><b>Going to apply the Database Changes...</b></td><tr>";
     for ($patch_count = 0; $patch_count < count($temp); $patch_count++) {
         //Here we have to include all the files (all db differences for each release will be included)
         $filename = "modules/Migration/DBChanges/" . $temp[$patch_count] . "_to_" . $temp[$patch_count + 1] . ".php";
         $empty_tag = "<tr><td colspan='2'>&nbsp;</td></tr>";
         $start_tag = "<tr><td colspan='2'><b><font color='red'>&nbsp;";
         $end_tag = "</font></b></td></tr>";
         if (is_file($filename)) {
             echo $empty_tag . $start_tag . $temp[$patch_count] . " ==> " . $temp[$patch_count + 1] . " Database changes -- Starts." . $end_tag;
             include $filename;
             //include the file which contains the corresponding db changes
             echo $start_tag . $temp[$patch_count] . " ==> " . $temp[$patch_count + 1] . " Database changes -- Ends." . $end_tag;
         }
     }
     //Here we have to update the version in table. so that when we do migration next time we will get the version
     $res = $adb->query('SELECT * FROM vtiger_version');
     global $vtiger_current_version;
     require dirname(__FILE__) . '/vtigerversion.php';
     if ($adb->num_rows($res)) {
         $res = ExecuteQuery("UPDATE vtiger_version SET old_version='{$versions[$source_version]}',current_version='{$vtiger_current_version}'");
         $completed = true;
     } else {
         ExecuteQuery("INSERT INTO vtiger_version (id, old_version, current_version) values (" . $adb->getUniqueID('vtiger_version') . ", '{$versions[$source_version]}', '{$vtiger_current_version}');");
         $completed = true;
     }
     echo '</table><br><br>';
     if ($completed == true) {
         echo "<script type='text/javascript'>window.parent.Migration_Complete();</script>";
     }
     create_tab_data_file();
     create_parenttab_data_file();
     if ($completed == true) {
         return true;
     }
 }