Ejemplo n.º 1
0
/**
 * This function returns the ec_blocks and its related information for given module.
 * Input Parameter are $module - module name, $disp_view = display view (edit,detail or create),$mode - edit, $col_fields - * column ec_fields/
 * This function returns an array
 */
function getBlocksForQuickEdit($module, $disp_view, $mode, $col_fields = '', $display_type_check)
{
    global $log;
    $log->debug("Entering getBlocksForQuickEdit() method ...");
    global $adb, $current_user;
    global $mod_strings;
    $tabid = getTabid($module);
    $block_detail = array();
    $getBlockinfo = "";
    $prev_header = "";
    $query = "select blockid,blocklabel,show_title from ec_blocks where tabid={$tabid} and {$disp_view}=0 and visible = 0 order by sequence";
    $result = $adb->query($query);
    $noofrows = $adb->num_rows($result);
    $blockid_list = '(';
    for ($i = 0; $i < $noofrows; $i++) {
        $blockid = $adb->query_result($result, $i, "blockid");
        if ($i != 0) {
            $blockid_list .= ', ';
        }
        $blockid_list .= $blockid;
        $block_label[$blockid] = $adb->query_result($result, $i, "blocklabel");
    }
    $blockid_list .= ')';
    //retreive the ec_profileList from database
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    if ($is_admin == true) {
        $sql = "SELECT ec_field.* FROM ec_field INNER JOIN ec_def_org_field ON ec_def_org_field.fieldid=ec_field.fieldid AND ec_def_org_field.visible=0 WHERE ec_field.tabid=" . $tabid . " AND ec_field.block IN " . $blockid_list . " AND " . $display_type_check . " ORDER BY block,sequence";
    } else {
        $profileList = getCurrentUserProfileList();
        $sql = "SELECT ec_field.*,ec_profile2field.readonly as profile_readonly FROM ec_field INNER JOIN ec_profile2field ON ec_profile2field.fieldid=ec_field.fieldid INNER JOIN ec_def_org_field ON ec_def_org_field.fieldid=ec_field.fieldid  WHERE ec_field.tabid=" . $tabid . " AND ec_field.block IN " . $blockid_list . " AND " . $display_type_check . " AND ec_def_org_field.visible=0 AND ec_profile2field.visible=0 AND ec_profile2field.profileid IN " . $profileList . " ORDER BY block,sequence";
    }
    $result = $adb->query($sql);
    $getBlockInfo = getBlockInformation($module, $result, $col_fields, $tabid, $block_label, $mode);
    $index_count = 1;
    $max_index = 0;
    if (!isset($getBlockInfo)) {
        $getBlockInfo = array();
    }
    foreach ($getBlockInfo as $label => $contents) {
        $no_rows = count($contents);
        $index_count = $max_index + 1;
        foreach ($contents as $block_row => $elements) {
            $max_index = $no_rows + $index_count;
            for ($i = 0; $i < count($elements); $i++) {
                if (isset($getBlockInfo[$label][$block_row][$i]) && sizeof($getBlockInfo[$label][$block_row][$i]) != 0) {
                    if ($i == 0) {
                        $getBlockInfo[$label][$block_row][$i][] = array($index_count);
                    } else {
                        $getBlockInfo[$label][$block_row][$i][] = array($max_index);
                    }
                }
            }
            $index_count++;
        }
    }
    $log->debug("Exiting getBlocksForQuickEdit method ...");
    return $getBlockInfo;
}
Ejemplo n.º 2
0
/**	function used to get the query which will list the permitted fields
 *	@param string $module - module name
 *	@param string $disp_view - view name, this may be create_view, edit_view or detail_view
 *	@return string $sql - query to get the list of fields which are permitted to the current user
 */
function getPermittedFieldsQuery($module, $disp_view)
{
    global $adb, $log;
    $log->debug("Entering into the function getPermittedFieldsQuery({$module}, {$disp_view})");
    global $current_user;
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    //To get the permitted blocks
    $blockid_list = getPermittedBlocks($module, $disp_view);
    $tabid = getTabid($module);
    if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || $module == "Users") {
        $sql = "SELECT vtiger_field.columnname, vtiger_field.fieldlabel, vtiger_field.tablename FROM vtiger_field WHERE vtiger_field.tabid=" . $tabid . " AND vtiger_field.block IN {$blockid_list} AND vtiger_field.displaytype IN (1,2,4) and vtiger_field.presence in (0,2) ORDER BY block,sequence";
    } else {
        $profileList = getCurrentUserProfileList();
        $sql = "SELECT vtiger_field.columnname, vtiger_field.fieldlabel, vtiger_field.tablename FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=" . $tabid . " AND vtiger_field.block IN " . $blockid_list . " AND vtiger_field.displaytype IN (1,2,4) AND vtiger_profile2field.visible=0 AND vtiger_def_org_field.visible=0 AND vtiger_profile2field.profileid IN (" . implode(",", $profileList) . ") and vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid ORDER BY block,sequence";
    }
    $log->debug("Exit from the function getPermittedFieldsQuery({$module}, {$disp_view}). Return value = {$sql}");
    return $sql;
}
Ejemplo n.º 3
0
 private function getaccesfield($module, $primodule, $secmodule)
 {
     $adb = PearDatabase::getInstance();
     $access_fields = array();
     $profileList = getCurrentUserProfileList();
     $query = "select vtiger_field.fieldname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where";
     $params = array();
     if ($module == "Calendar") {
         $query .= " vtiger_field.tabid in (9,16) and vtiger_field.displaytype in (1,2,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
         if (count($profileList) > 0) {
             $query .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")";
             array_push($params, $profileList);
         }
         $query .= " group by vtiger_field.fieldid order by block,sequence";
     } else {
         array_push($params, $primodule, $secmodule);
         $query .= " vtiger_field.tabid in (select tabid from vtiger_tab where vtiger_tab.name in (?,?)) and vtiger_field.displaytype in (1,2,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
         if (count($profileList) > 0) {
             $query .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")";
             array_push($params, $profileList);
         }
         $query .= " group by vtiger_field.fieldid order by block,sequence";
     }
     $result = $adb->pquery($query, $params);
     while ($collistrow = $adb->fetch_array($result)) {
         $access_fields[] = $collistrow["fieldname"];
     }
     return $access_fields;
 }
Ejemplo n.º 4
0
 /**
  * Function to get calendar query for outlookplugin
  * @param   string    $username     -  User name
  * @return  string    $query        -  sql query
  */
 function get_calendarsforol($user_name)
 {
     global $log, $adb, $current_user;
     $log->debug("Entering get_calendarsforol(" . $user_name . ") method ...");
     require_once "modules/Users/Users.php";
     $seed_user = new Users();
     $user_id = $seed_user->retrieve_user_id($user_name);
     $current_user = $seed_user;
     $current_user->retrieve_entity_info($user_id, 'Users');
     require 'user_privileges/user_privileges_' . $current_user->id . '.php';
     require 'user_privileges/sharing_privileges_' . $current_user->id . '.php';
     if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
         $sql1 = "select tablename,columnname from vtiger_field where tabid=9 and tablename <> 'vtiger_recurringevents' and tablename <> 'vtiger_activity_reminder' and vtiger_field.presence in (0,2)";
         $params1 = array();
     } else {
         $profileList = getCurrentUserProfileList();
         $sql1 = "select tablename,columnname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=9 and tablename <> 'vtiger_recurringevents' and tablename <> 'vtiger_activity_reminder' and vtiger_field.displaytype in (1,2,4,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
         $params1 = array();
         if (count($profileList) > 0) {
             $sql1 .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")";
             array_push($params1, $profileList);
         }
     }
     $result1 = $adb->pquery($sql1, $params1);
     for ($i = 0; $i < $adb->num_rows($result1); $i++) {
         $permitted_lists[] = $adb->query_result($result1, $i, 'tablename');
         $permitted_lists[] = $adb->query_result($result1, $i, 'columnname');
         if ($adb->query_result($result1, $i, 'columnname') == "date_start") {
             $permitted_lists[] = 'vtiger_activity';
             $permitted_lists[] = 'time_start';
         }
         if ($adb->query_result($result1, $i, 'columnname') == "due_date") {
             $permitted_lists[] = 'vtiger_activity';
             $permitted_lists[] = 'time_end';
         }
     }
     $permitted_lists = array_chunk($permitted_lists, 2);
     $column_table_lists = array();
     for ($i = 0; $i < count($permitted_lists); $i++) {
         $column_table_lists[] = implode(".", $permitted_lists[$i]);
     }
     $query = "select vtiger_activity.activityid as clndrid, " . implode(',', $column_table_lists) . " from vtiger_activity\n\t\t\tinner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.activityid=vtiger_activity.activityid\n\t\t\tinner join vtiger_users on vtiger_users.id=vtiger_salesmanactivityrel.smid\n\t\t\tleft join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid=vtiger_activity.activityid\n\t\t\tleft join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_cntactivityrel.contactid\n\t\t\tleft join vtiger_seactivityrel on vtiger_seactivityrel.activityid = vtiger_activity.activityid\n\t\t\tinner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid\n\t\t\twhere vtiger_users.user_name='" . $user_name . "' and vtiger_crmentity.deleted=0 and vtiger_activity.activitytype='Meeting'";
     $log->debug("Exiting get_calendarsforol method ...");
     return $query;
 }
 /** Function to insert values in the specifed table for the specified module
  * @param $table_name -- table name:: Type varchar
  * @param $module -- module:: Type varchar
  */
 function insertIntoEntityTable($table_name, $module, $fileid = '')
 {
     global $log;
     global $current_user, $app_strings;
     $log->info("function insertIntoEntityTable " . $module . ' vtiger_table name ' . $table_name);
     global $adb;
     $insertion_mode = $this->mode;
     //Checkin whether an entry is already is present in the vtiger_table to update
     if ($insertion_mode == 'edit') {
         $tablekey = $this->tab_name_index[$table_name];
         // Make selection on the primary key of the module table to check.
         $check_query = "select {$tablekey} from {$table_name} where {$tablekey}=?";
         $check_result = $adb->pquery($check_query, array($this->id));
         $num_rows = $adb->num_rows($check_result);
         if ($num_rows <= 0) {
             $insertion_mode = '';
         }
     }
     $tabid = getTabid($module);
     if ($module == 'Calendar' && $this->column_fields["activitytype"] != null && $this->column_fields["activitytype"] != 'Task') {
         $tabid = getTabid('Events');
     }
     if ($insertion_mode == 'edit') {
         $update = array();
         $update_params = array();
         checkFileAccessForInclusion('user_privileges/user_privileges_' . $current_user->id . '.php');
         require 'user_privileges/user_privileges_' . $current_user->id . '.php';
         if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
             $sql = "select * from vtiger_field where tabid in (" . generateQuestionMarks($tabid) . ") and tablename=? and displaytype in (1,3) and presence in (0,2) group by columnname";
             $params = array($tabid, $table_name);
         } else {
             $profileList = getCurrentUserProfileList();
             if (count($profileList) > 0) {
                 $sql = "SELECT *\n\t\t\t  \t\t\tFROM vtiger_field\n\t\t\t  \t\t\tINNER JOIN vtiger_profile2field\n\t\t\t  \t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t  \t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t  \t\t\tAND vtiger_profile2field.visible = 0 AND vtiger_profile2field.readonly = 0\n\t\t\t  \t\t\tAND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")\n\t\t\t  \t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.tablename=? and vtiger_field.displaytype in (1,3) and vtiger_field.presence in (0,2) group by columnname";
                 $params = array($tabid, $profileList, $table_name);
             } else {
                 $sql = "SELECT *\n\t\t\t  \t\t\tFROM vtiger_field\n\t\t\t  \t\t\tINNER JOIN vtiger_profile2field\n\t\t\t  \t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t  \t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t  \t\t\tAND vtiger_profile2field.visible = 0 AND vtiger_profile2field.readonly = 0\n\t\t\t  \t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.tablename=? and vtiger_field.displaytype in (1,3) and vtiger_field.presence in (0,2) group by columnname";
                 $params = array($tabid, $table_name);
             }
         }
     } else {
         $table_index_column = $this->tab_name_index[$table_name];
         if ($table_index_column == 'id' && $table_name == 'vtiger_users') {
             $currentuser_id = $adb->getUniqueID("vtiger_users");
             $this->id = $currentuser_id;
         }
         $column = array($table_index_column);
         $value = array($this->id);
         $sql = "select * from vtiger_field where tabid=? and tablename=? and displaytype in (1,3,4) and vtiger_field.presence in (0,2)";
         $params = array($tabid, $table_name);
     }
     // Attempt to re-use the quer-result to avoid reading for every save operation
     // TODO Need careful analysis on impact ... MEMORY requirement might be more
     static $_privatecache = array();
     $cachekey = "{$insertion_mode}-" . implode(',', $params);
     if (!isset($_privatecache[$cachekey])) {
         $result = $adb->pquery($sql, $params);
         $noofrows = $adb->num_rows($result);
         if (CRMEntity::isBulkSaveMode()) {
             $cacheresult = array();
             for ($i = 0; $i < $noofrows; ++$i) {
                 $cacheresult[] = $adb->fetch_array($result);
             }
             $_privatecache[$cachekey] = $cacheresult;
         }
     } else {
         // Useful when doing bulk save
         $result = $_privatecache[$cachekey];
         $noofrows = count($result);
     }
     for ($i = 0; $i < $noofrows; $i++) {
         $fieldname = $this->resolve_query_result_value($result, $i, "fieldname");
         $columname = $this->resolve_query_result_value($result, $i, "columnname");
         $uitype = $this->resolve_query_result_value($result, $i, "uitype");
         $generatedtype = $this->resolve_query_result_value($result, $i, "generatedtype");
         $typeofdata = $this->resolve_query_result_value($result, $i, "typeofdata");
         $typeofdata_array = explode("~", $typeofdata);
         $datatype = $typeofdata_array[0];
         $ajaxSave = false;
         if ($_REQUEST['file'] == 'DetailViewAjax' && $_REQUEST['ajxaction'] == 'DETAILVIEW' && isset($_REQUEST["fldName"]) && $_REQUEST["fldName"] != $fieldname || $_REQUEST['action'] == 'MassEditSave' && !isset($_REQUEST[$fieldname . "_mass_edit_check"])) {
             $ajaxSave = true;
         }
         if ($uitype == 4 && $insertion_mode != 'edit') {
             $fldvalue = '';
             // Bulk Save Mode: Avoid generation of module sequence number, take care later.
             // SalesPlatform.ru begin: Added separate numbering for self organizations
             if (!CRMEntity::isBulkSaveMode()) {
                 $modules = array('Invoice', 'Act', 'Consignment');
                 if (in_array($module, $modules) && isset($this->column_fields['spcompany'])) {
                     $fldvalue = $this->setModuleSeqNumber("increment", $module, '', '', $this->column_fields['spcompany']);
                 } else {
                     $fldvalue = $this->setModuleSeqNumber("increment", $module);
                 }
                 //$fldvalue = $this->setModuleSeqNumber("increment", $module);
             }
             // SalesPlatform.ru end
             $this->column_fields[$fieldname] = $fldvalue;
         }
         if (isset($this->column_fields[$fieldname])) {
             if ($uitype == 56) {
                 if ($this->column_fields[$fieldname] == 'on' || $this->column_fields[$fieldname] == 1) {
                     $fldvalue = '1';
                 } else {
                     $fldvalue = '0';
                 }
             } elseif ($uitype == 15 || $uitype == 16) {
                 if ($this->column_fields[$fieldname] == $app_strings['LBL_NOT_ACCESSIBLE']) {
                     //If the value in the request is Not Accessible for a picklist, the existing value will be replaced instead of Not Accessible value.
                     $sql = "select {$columname} from  {$table_name} where " . $this->tab_name_index[$table_name] . "=?";
                     $res = $adb->pquery($sql, array($this->id));
                     $pick_val = $adb->query_result($res, 0, $columname);
                     $fldvalue = $pick_val;
                 } else {
                     $fldvalue = $this->column_fields[$fieldname];
                 }
             } elseif ($uitype == 33) {
                 if (is_array($this->column_fields[$fieldname])) {
                     $field_list = implode(' |##| ', $this->column_fields[$fieldname]);
                 } else {
                     $field_list = $this->column_fields[$fieldname];
                 }
                 if ($field_list == '') {
                     $fldvalue = NULL;
                 } else {
                     $fldvalue = $field_list;
                 }
             } elseif ($uitype == 5 || $uitype == 6 || $uitype == 23) {
                 //Added to avoid function call getDBInsertDateValue in ajax save
                 if (isset($current_user->date_format) && !$ajaxSave) {
                     $fldvalue = getValidDBInsertDateValue($this->column_fields[$fieldname]);
                 } else {
                     $fldvalue = $this->column_fields[$fieldname];
                 }
             } elseif ($uitype == 7) {
                 //strip out the spaces and commas in numbers if given ie., in amounts there may be ,
                 $fldvalue = str_replace(",", "", $this->column_fields[$fieldname]);
                 //trim($this->column_fields[$fieldname],",");
             } elseif ($uitype == 26) {
                 if (empty($this->column_fields[$fieldname])) {
                     $fldvalue = 1;
                     //the documents will stored in default folder
                 } else {
                     $fldvalue = $this->column_fields[$fieldname];
                 }
             } elseif ($uitype == 28) {
                 if ($this->column_fields[$fieldname] == null) {
                     $fileQuery = $adb->pquery("SELECT filename from vtiger_notes WHERE notesid = ?", array($this->id));
                     $fldvalue = null;
                     if (isset($fileQuery)) {
                         $rowCount = $adb->num_rows($fileQuery);
                         if ($rowCount > 0) {
                             $fldvalue = decode_html($adb->query_result($fileQuery, 0, 'filename'));
                         }
                     }
                 } else {
                     $fldvalue = decode_html($this->column_fields[$fieldname]);
                 }
             } elseif ($uitype == 8) {
                 $this->column_fields[$fieldname] = rtrim($this->column_fields[$fieldname], ',');
                 $ids = explode(',', $this->column_fields[$fieldname]);
                 $json = new Zend_Json();
                 $fldvalue = $json->encode($ids);
             } elseif ($uitype == 12) {
                 // Bulk Sae Mode: Consider the FROM email address as specified, if not lookup
                 $fldvalue = $this->column_fields[$fieldname];
                 if (empty($fldvalue)) {
                     $query = "SELECT email1 FROM vtiger_users WHERE id = ?";
                     $res = $adb->pquery($query, array($current_user->id));
                     $rows = $adb->num_rows($res);
                     if ($rows > 0) {
                         $fldvalue = $adb->query_result($res, 0, 'email1');
                     }
                 }
                 // END
             } elseif ($uitype == 72 && !$ajaxSave) {
                 // Some of the currency fields like Unit Price, Totoal , Sub-total - doesn't need currency conversion during save
                 $fldvalue = CurrencyField::convertToDBFormat($this->column_fields[$fieldname], null, true);
             } elseif ($uitype == 71 && !$ajaxSave) {
                 $fldvalue = CurrencyField::convertToDBFormat($this->column_fields[$fieldname]);
             } else {
                 $fldvalue = $this->column_fields[$fieldname];
             }
             if ($uitype != 33 && $uitype != 8) {
                 $fldvalue = from_html($fldvalue, $insertion_mode == 'edit' ? true : false);
             }
         } else {
             $fldvalue = '';
         }
         if ($fldvalue == '') {
             $fldvalue = $this->get_column_value($columname, $fldvalue, $fieldname, $uitype, $datatype);
         }
         if ($insertion_mode == 'edit') {
             if ($table_name != 'vtiger_ticketcomments' && $uitype != 4) {
                 array_push($update, $columname . "=?");
                 array_push($update_params, $fldvalue);
             }
         } else {
             array_push($column, $columname);
             array_push($value, $fldvalue);
         }
     }
     if ($insertion_mode == 'edit') {
         if ($module == 'Potentials') {
             $dbquery = 'select sales_stage from vtiger_potential where potentialid = ?';
             $sales_stage = $adb->query_result($adb->pquery($dbquery, array($this->id)), 0, 'sales_stage');
             if ($sales_stage != $_REQUEST['sales_stage'] && $_REQUEST['sales_stage'] != '') {
                 $date_var = date("Y-m-d H:i:s");
                 $closingDateField = new DateTimeField($this->column_fields['closingdate']);
                 $closingdate = $_REQUEST['ajxaction'] == 'DETAILVIEW' ? $this->column_fields['closingdate'] : $closingDateField->getDBInsertDateValue();
                 $sql = "insert into vtiger_potstagehistory values(?,?,?,?,?,?,?,?)";
                 $params = array('', $this->id, $this->column_fields['amount'], decode_html($sales_stage), $this->column_fields['probability'], 0, $adb->formatDate($closingdate, true), $adb->formatDate($date_var, true));
                 $adb->pquery($sql, $params);
             }
         } elseif ($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice' || $module == 'Act' || $module == 'Consignment') {
             //elseif ($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice') {
             // SalesPlatform.ru end
             //added to update the history for PO, SO, Quotes and Invoice
             $history_field_array = array("Act" => "sp_actstatus", "Consignment" => "sp_consignmentstatus", "PurchaseOrder" => "postatus", "SalesOrder" => "sostatus", "Quotes" => "quotestage", "Invoice" => "invoicestatus");
             $inventory_module = $module;
             if ($_REQUEST['ajxaction'] == 'DETAILVIEW') {
                 //if we use ajax edit
                 if ($inventory_module == "PurchaseOrder") {
                     $relatedname = getVendorName($this->column_fields['vendor_id']);
                 } else {
                     $relatedname = getAccountName($this->column_fields['account_id']);
                 }
                 $total = $this->column_fields['hdnGrandTotal'];
             } else {
                 //using edit button and save
                 if ($inventory_module == "PurchaseOrder") {
                     $relatedname = $_REQUEST["vendor_name"];
                 } else {
                     $relatedname = $_REQUEST["account_name"];
                 }
                 $total = $_REQUEST['total'];
             }
             if ($this->column_fields["{$history_field_array[$inventory_module]}"] == $app_strings['LBL_NOT_ACCESSIBLE']) {
                 //If the value in the request is Not Accessible for a picklist, the existing value will be replaced instead of Not Accessible value.
                 $his_col = $history_field_array[$inventory_module];
                 $his_sql = "select {$his_col} from  {$this->table_name} where " . $this->table_index . "=?";
                 $his_res = $adb->pquery($his_sql, array($this->id));
                 $status_value = $adb->query_result($his_res, 0, $his_col);
                 $stat_value = $status_value;
             } else {
                 $stat_value = $this->column_fields["{$history_field_array[$inventory_module]}"];
             }
             $oldvalue = getSingleFieldValue($this->table_name, $history_field_array[$inventory_module], $this->table_index, $this->id);
             if ($this->column_fields["{$history_field_array[$inventory_module]}"] != '' && $oldvalue != $stat_value) {
                 addInventoryHistory($inventory_module, $this->id, $relatedname, $total, $stat_value);
             }
         }
         //Check done by Don. If update is empty the the query fails
         if (count($update) > 0) {
             $sql1 = "update {$table_name} set " . implode(",", $update) . " where " . $this->tab_name_index[$table_name] . "=?";
             array_push($update_params, $this->id);
             $adb->pquery($sql1, $update_params);
         }
     } else {
         $sql1 = "insert into {$table_name}(" . implode(",", $column) . ") values(" . generateQuestionMarks($value) . ")";
         $adb->pquery($sql1, $value);
     }
 }
Ejemplo n.º 6
0
/** Function to check permission to access a vtiger_field for a given user
 * @param $fld_module -- Module :: Type String
 * @param $userid -- User Id :: Type integer
 * @param $fieldname -- Field Name :: Type varchar
 * @returns $rolename -- Role Name :: Type varchar
 *
 */
function getFieldVisibilityPermission($fld_module, $userid, $fieldname, $accessmode = 'readonly')
{
    $log = vglobal('log');
    $log->debug("Entering getFieldVisibilityPermission(" . $fld_module . "," . $userid . "," . $fieldname . ") method ...");
    $adb = PearDatabase::getInstance();
    $current_user = vglobal('current_user');
    // Check if field is in-active
    $fieldActive = isFieldActive($fld_module, $fieldname);
    if ($fieldActive == false) {
        return '1';
    }
    require 'user_privileges/user_privileges_' . $userid . '.php';
    /* Asha: Fix for ticket #4508. Users with View all and Edit all permission will also have visibility permission for all fields */
    if ($is_admin || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
        $log->debug("Exiting getFieldVisibilityPermission method ...");
        return '0';
    } else {
        //get vtiger_profile list using userid
        $profilelist = getCurrentUserProfileList();
        //get tabid
        $tabid = getTabid($fld_module);
        if (count($profilelist) > 0) {
            if ($accessmode == 'readonly') {
                $query = "SELECT vtiger_profile2field.visible FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=? AND vtiger_profile2field.visible=0 AND vtiger_def_org_field.visible=0  AND vtiger_profile2field.profileid in (" . generateQuestionMarks($profilelist) . ") AND vtiger_field.fieldname= ? and vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid";
            } else {
                $query = "SELECT vtiger_profile2field.visible FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=? AND vtiger_profile2field.visible=0 AND vtiger_profile2field.readonly=0 AND vtiger_def_org_field.visible=0  AND vtiger_profile2field.profileid in (" . generateQuestionMarks($profilelist) . ") AND vtiger_field.fieldname= ? and vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid";
            }
            $params = array($tabid, $profilelist, $fieldname);
        } else {
            if ($accessmode == 'readonly') {
                $query = "SELECT vtiger_profile2field.visible FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=? AND vtiger_profile2field.visible=0 AND vtiger_def_org_field.visible=0  AND vtiger_field.fieldname= ? and vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid";
            } else {
                $query = "SELECT vtiger_profile2field.visible FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=? AND vtiger_profile2field.visible=0 AND vtiger_profile2field.readonly=0 AND vtiger_def_org_field.visible=0  AND vtiger_field.fieldname= ? and vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid";
            }
            $params = array($tabid, $fieldname);
        }
        //Postgres 8 fixes
        if ($adb->isPostgres()) {
            $query = fixPostgresQuery($query, $log, 0);
        }
        $result = $adb->pquery($query, $params);
        $log->debug("Exiting getFieldVisibilityPermission method ...");
        // Returns value as a string
        if ($adb->num_rows($result) == 0) {
            return '1';
        }
        return $adb->query_result($result, "0", "visible") . "";
    }
}
Ejemplo n.º 7
0
function getSearchListViewEntries($focus, $module, $list_result, $navigation_array, $form = '')
{
    global $log;
    $log->debug("Entering getSearchListViewEntries(" . get_class($focus) . "," . $module . "," . $list_result . "," . $navigation_array . ") method ...");
    global $adb, $app_strings, $theme, $current_user, $list_max_entries_per_page;
    $noofrows = $adb->num_rows($list_result);
    $list_header = '';
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    $list_block = array();
    //getting the vtiger_fieldtable entries from database
    $tabid = getTabid($module);
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    //Added to reduce the no. of queries logging for non-admin user -- by Minnie-start
    $field_list = array();
    $j = 0;
    foreach ($focus->search_fields as $name => $tableinfo) {
        $fieldname = $focus->search_fields_name[$name];
        array_push($field_list, $fieldname);
        $j++;
    }
    $field = array();
    if ($is_admin == false && $module != 'Users') {
        if ($module == 'Emails') {
            $query = "SELECT fieldname FROM vtiger_field WHERE tabid = ? and vtiger_field.presence in (0,2)";
            $params = array($tabid);
        } else {
            $profileList = getCurrentUserProfileList();
            $query = "SELECT DISTINCT vtiger_field.fieldname\n\t\t\t\tFROM vtiger_field\n\t\t\t\tINNER JOIN vtiger_profile2field\n\t\t\t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t\tAND vtiger_profile2field.visible = 0\n\t\t\t\tAND vtiger_def_org_field.visible = 0\n\t\t\t\tAND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")\n\t\t\t\tAND vtiger_field.fieldname IN (" . generateQuestionMarks($field_list) . ") and vtiger_field.presence in (0,2)";
            $params = array($tabid, $profileList, $field_list);
        }
        $result = $adb->pquery($query, $params);
        for ($k = 0; $k < $adb->num_rows($result); $k++) {
            $field[] = $adb->query_result($result, $k, "fieldname");
        }
    }
    //constructing the uitype and columnname array
    $ui_col_array = array();
    $query = "SELECT uitype, columnname, fieldname\n\t\tFROM vtiger_field\n\t\tWHERE tabid=?\n\t\tAND fieldname IN (" . generateQuestionMarks($field_list) . ") and vtiger_field.presence in (0,2)";
    $result = $adb->pquery($query, array($tabid, $field_list));
    $num_rows = $adb->num_rows($result);
    for ($i = 0; $i < $num_rows; $i++) {
        $tempArr = array();
        $uitype = $adb->query_result($result, $i, 'uitype');
        $columnname = $adb->query_result($result, $i, 'columnname');
        $field_name = $adb->query_result($result, $i, 'fieldname');
        $tempArr[$uitype] = $columnname;
        $ui_col_array[$field_name] = $tempArr;
    }
    //end
    if ($navigation_array['end_val'] > 0) {
        for ($i = 1; $i <= $noofrows; $i++) {
            //Getting the entityid
            if ($module != 'Users') {
                $entity_id = $adb->query_result($list_result, $i - 1, "crmid");
            } else {
                $entity_id = $adb->query_result($list_result, $i - 1, "id");
            }
            $list_header = array();
            foreach ($focus->search_fields as $name => $tableinfo) {
                $fieldname = $focus->search_fields_name[$name];
                if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || in_array($fieldname, $field) || $module == 'Users') {
                    if ($fieldname == '') {
                        $table_name = '';
                        $column_name = '';
                        foreach ($tableinfo as $tablename => $colname) {
                            $table_name = $tablename;
                            $column_name = $colname;
                        }
                        $value = $adb->query_result($list_result, $i - 1, $colname);
                    } else {
                        if (($module == 'Calls' || $module == 'Tasks' || $module == 'Meetings' || $module == 'Emails') && ($name == 'Related to' || $name == 'Contact Name' || $name == 'Vendor Name')) {
                            if ($name == 'Related to') {
                                $value = getRelatedTo($module, $list_result, $i - 1);
                            }
                            if ($name == 'Contact Name') {
                                $contact_id = $adb->query_result($list_result, $i - 1, "contactid");
                                $contact_name = getFullNameFromQResult($list_result, $i - 1, "Contacts");
                                $value = "";
                                if ($contact_name != "" && $contact_id != 'NULL') {
                                    $value = "<a href='index.php?module=Contacts&action=DetailView&record=" . $contact_id . "'>" . $contact_name . "</a>";
                                }
                            }
                        } elseif (($module == 'Faq' || $module == 'Documents') && $name == 'Related to') {
                            $value = getRelatedToEntity($module, $list_result, $i - 1);
                        } elseif ($name == 'Account Name' && ($module == 'Potentials' || $module == 'SalesOrder' || $module == 'Quotes')) {
                            $account_id = $adb->query_result($list_result, $i - 1, "accountid");
                            $account_name = getAccountName($account_id);
                            $value = textlength_check($account_name);
                        } elseif ($name == 'Quote Name' && $module == 'SalesOrder') {
                            $quote_id = $adb->query_result($list_result, $i - 1, "quoteid");
                            $quotename = getQuoteName($quote_id);
                            $value = textlength_check($quotename);
                        } elseif ($name == 'Account Name' && $module == 'Contacts') {
                            $account_id = $adb->query_result($list_result, $i - 1, "accountid");
                            $account_name = getAccountName($account_id);
                            $value = textlength_check($account_name);
                        } elseif (isset($focus->popup_fields) && in_array($fieldname, $focus->popup_fields)) {
                            global $default_charset;
                            $forfield = htmlspecialchars($_REQUEST['forfield'], ENT_QUOTES, $default_charset);
                            $list_result_count = $i - 1;
                            $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "search", $focus->popup_type);
                            if (isset($forfield) && $forfield != '' && $focus->popup_type != 'detailview') {
                                $value = strip_tags($value);
                                // Remove any previous html conversion
                                $value = "<a href='javascript:window.close();' onclick='return vtlib_setvalue_from_popup({$entity_id}, \"{$value}\", \"{$forfield}\")'>{$value}</a>";
                            }
                        } else {
                            $list_result_count = $i - 1;
                            $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "search", $focus->popup_type, $form);
                        }
                    }
                    $list_header[] = $value;
                }
            }
            if ($module == 'Products' && ($focus->popup_type == 'inventory_prod' || $focus->popup_type == 'inventory_prod_po')) {
                global $default_charset;
                require 'user_privileges/user_privileges_' . $current_user->id . '.php';
                $row_id = $_REQUEST['curr_row'];
                //To get all the tax types and values and pass it to product details
                $tax_str = '';
                $tax_details = getAllTaxes();
                for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                    $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
                }
                $tax_str = trim($tax_str, ',');
                $rate = $user_info['conv_rate'];
                if (getFieldVisibilityPermission($module, $current_user->id, 'unit_price') == '0') {
                    $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                    if ($_REQUEST['currencyid'] != null) {
                        $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id));
                        $unitprice = $prod_prices[$entity_id];
                    }
                } else {
                    $unit_price = '';
                }
                $sub_products = '';
                $sub_prod = '';
                $sub_prod_query = $adb->pquery("SELECT vtiger_products.productid,vtiger_products.productname from vtiger_products INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid INNER JOIN vtiger_seproductsrel on vtiger_seproductsrel.crmid=vtiger_products.productid WHERE vtiger_seproductsrel.productid=? and vtiger_seproductsrel.setype='Products'", array($entity_id));
                for ($k = 0; $k < $adb->num_rows($sub_prod_query); $k++) {
                    //$sub_prod=array();
                    $id = $adb->query_result($sub_prod_query, $k, "productid");
                    $str_sep = '';
                    if ($k > 0) {
                        $str_sep = ":";
                    }
                    $sub_products .= $str_sep . $id;
                    $sub_prod .= $str_sep . " - " . $adb->query_result($sub_prod_query, $k, "productname");
                }
                $sub_det = $sub_products . "::" . str_replace(":", "<br>", $sub_prod);
                $qty_stock = $adb->query_result($list_result, $list_result_count, 'qtyinstock');
                $slashes_temp_val = popup_from_html(getProductName($entity_id));
                $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                $description = $adb->query_result($list_result, $list_result_count, 'description');
                $slashes_desc = htmlspecialchars($description, ENT_QUOTES, $default_charset);
                $sub_products_link = '<a href="index.php?module=Products&action=Popup&html=Popup_picker&return_module=' . vtlib_purify($_REQUEST['return_module']) . '&record_id=' . vtlib_purify($entity_id) . '&form=HelpDeskEditView&select=enable&popuptype=' . $focus->popup_type . '&curr_row=' . vtlib_purify($row_id) . '&currencyid=' . vtlib_purify($_REQUEST['currencyid']) . '" > Sub Products</a>';
                if (!isset($_REQUEST['record_id'])) {
                    $sub_products_query = $adb->pquery("SELECT * from vtiger_seproductsrel WHERE productid=? AND setype='Products'", array($entity_id));
                    if ($adb->num_rows($sub_products_query) > 0) {
                        $list_header[] = $sub_products_link;
                    } else {
                        $list_header[] = $app_strings['LBL_NO_SUB_PRODUCTS'];
                    }
                }
            }
            if ($module == 'Services' && $focus->popup_type == 'inventory_service') {
                global $default_charset;
                require 'user_privileges/user_privileges_' . $current_user->id . '.php';
                $row_id = $_REQUEST['curr_row'];
                //To get all the tax types and values and pass it to product details
                $tax_str = '';
                $tax_details = getAllTaxes();
                for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                    $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
                }
                $tax_str = trim($tax_str, ',');
                $rate = $user_info['conv_rate'];
                if (getFieldVisibilityPermission($module, $current_user->id, 'unit_price') == '0') {
                    $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                    if ($_REQUEST['currencyid'] != null) {
                        $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id), $module);
                        $unitprice = $prod_prices[$entity_id];
                    }
                } else {
                    $unit_price = '';
                }
                $slashes_temp_val = popup_from_html($adb->query_result($list_result, $list_result_count, 'servicename'));
                $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                $description = $adb->query_result($list_result, $list_result_count, 'description');
                $slashes_desc = htmlspecialchars($description, ENT_QUOTES, $default_charset);
            }
            $list_block[$entity_id] = $list_header;
        }
    }
    $list = $list_block;
    $log->debug("Exiting getSearchListViewEntries method ...");
    return $list;
}
Ejemplo n.º 8
0
 /** Function to get the Columnnames of the Leads Record
  * Used By vtigerCRM Word Plugin
  * Returns the Merge Fields for Word Plugin
  */
 function getColumnNames_Lead()
 {
     $log = vglobal('log');
     $current_user = vglobal('current_user');
     $log->debug("Entering getColumnNames_Lead() method ...");
     require 'user_privileges/user_privileges_' . $current_user->id . '.php';
     if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
         $sql1 = "select fieldlabel from vtiger_field where tabid=7 and vtiger_field.presence in (0,2)";
         $params1 = array();
     } else {
         $profileList = getCurrentUserProfileList();
         $sql1 = "select vtiger_field.fieldid,fieldlabel from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=7 and vtiger_field.displaytype in (1,2,3,4) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
         $params1 = array();
         if (count($profileList) > 0) {
             $sql1 .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")  group by fieldid";
             array_push($params1, $profileList);
         }
     }
     $result = $this->db->pquery($sql1, $params1);
     $numRows = $this->db->num_rows($result);
     for ($i = 0; $i < $numRows; $i++) {
         $custom_fields[$i] = $this->db->query_result($result, $i, "fieldlabel");
         $custom_fields[$i] = preg_replace("/\\s+/", "", $custom_fields[$i]);
         $custom_fields[$i] = strtoupper($custom_fields[$i]);
     }
     $mergeflds = $custom_fields;
     $log->debug("Exiting getColumnNames_Lead method ...");
     return $mergeflds;
 }
Ejemplo n.º 9
0
/**
 * Function to get the where condition for a module based on the field table entries
 * @param  string $listquery  -- ListView query for the module
 * @param  string $module     -- module name
 * @param  string $search_val -- entered search string value
 * @return string $where      -- where condition for the module based on field table entries
 */
function getUnifiedWhere($listquery, $module, $search_val)
{
    global $adb, $current_user;
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    $search_val = $adb->sql_escape_string($search_val);
    if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
        $query = "SELECT columnname, tablename FROM vtiger_field WHERE tabid = ? and vtiger_field.presence in (0,2)";
        $qparams = array(getTabid($module));
    } else {
        $profileList = getCurrentUserProfileList();
        $query = "SELECT columnname, tablename FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid = vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid = vtiger_field.fieldid WHERE vtiger_field.tabid = ? AND vtiger_profile2field.visible = 0 AND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ") AND vtiger_def_org_field.visible = 0 and vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid";
        $qparams = array(getTabid($module), $profileList);
    }
    $result = $adb->pquery($query, $qparams);
    $noofrows = $adb->num_rows($result);
    $where = '';
    for ($i = 0; $i < $noofrows; $i++) {
        $columnname = $adb->query_result($result, $i, 'columnname');
        $tablename = $adb->query_result($result, $i, 'tablename');
        // Search / Lookup customization
        if ($module == 'Contacts' && $columnname == 'accountid') {
            $columnname = "accountname";
            $tablename = "vtiger_account";
        }
        // END
        //Before form the where condition, check whether the table for the field has been added in the listview query
        if (strstr($listquery, $tablename)) {
            if ($where != '') {
                $where .= " OR ";
            }
            $where .= $tablename . "." . $columnname . " LIKE '" . formatForSqlLike($search_val) . "'";
        }
    }
    return $where;
}
Ejemplo n.º 10
0
 function plugin_process_list_query($query)
 {
     global $log, $adb, $current_user;
     $log->debug("Entering process_list_query1(" . $query . ") method ...");
     $permitted_field_lists = array();
     require 'user_privileges/user_privileges_' . $current_user->id . '.php';
     if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
         $sql1 = "select columnname from vtiger_field where tabid=7 and block <> 75 and vtiger_field.presence in (0,2)";
         $params1 = array();
     } else {
         $profileList = getCurrentUserProfileList();
         $sql1 = "select columnname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=7 and vtiger_field.block <> 6 and vtiger_field.block <> 75 and vtiger_field.displaytype in (1,2,4,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
         $params1 = array();
         if (count($profileList) > 0) {
             $sql1 .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")";
             array_push($params1, $profileList);
         }
     }
     $result1 = $this->db->pquery($sql1, $params1);
     for ($i = 0; $i < $adb->num_rows($result1); $i++) {
         $permitted_field_lists[] = $adb->query_result($result1, $i, 'columnname');
     }
     $result =& $this->db->query($query, true, "Error retrieving {$this->object_name} list: ");
     $list = array();
     $rows_found = $this->db->getRowCount($result);
     if ($rows_found != 0) {
         for ($index = 0, $row = $this->db->fetchByAssoc($result, $index); $row && $index < $rows_found; $index++, $row = $this->db->fetchByAssoc($result, $index)) {
             $lead = array();
             $lead[lastname] = in_array("lastname", $permitted_field_lists) ? $row[lastname] : "";
             $lead[firstname] = in_array("firstname", $permitted_field_lists) ? $row[firstname] : "";
             $lead[email] = in_array("email", $permitted_field_lists) ? $row[email] : "";
             $lead[leadid] = $row[leadid];
             $lead[company] = in_array("company", $permitted_field_lists) ? $row[company] : "";
             $list[] = $lead;
         }
     }
     $response = array();
     $response['list'] = $list;
     $response['row_count'] = $rows_found;
     $response['next_offset'] = $next_offset;
     $response['previous_offset'] = $previous_offset;
     $log->debug("Exiting process_list_query1 method ...");
     return $response;
 }
Ejemplo n.º 11
0
function getAllModulesWithDateTimeFields()
{
    global $adb, $log, $current_user;
    if (is_admin($current_user)) {
        $sqlmods = 'SELECT distinct cbfld.tabid,vtiger_tab.name
			FROM vtiger_field as cbfld
			INNER JOIN vtiger_tab on cbfld.tabid = vtiger_tab.tabid
			WHERE vtiger_tab.presence=0 and vtiger_tab.isentitytype=1 and uitype=5';
        $params = array();
    } else {
        $sqlmods = '';
        $profileList = getCurrentUserProfileList();
        $sql = "select * from vtiger_profile2globalpermissions where globalactionid=1 and  profileid in (" . generateQuestionMarks($profileList) . ");";
        $result = $adb->pquery($sql, array($profileList));
        if ($result and $adb->num_rows($result) > 0) {
            for ($i = 0; $i < $adb->num_rows($result); $i++) {
                $permission = $adb->query_result($result, $i, 'globalactionpermission');
                if ($permission != 1 || $permission != '1') {
                    // can see everything
                    $sqlmods = 'SELECT distinct cbfld.tabid,vtiger_tab.name
						FROM vtiger_field as cbfld
						INNER JOIN vtiger_tab on cbfld.tabid = vtiger_tab.tabid
						WHERE vtiger_tab.presence=0 and vtiger_tab.isentitytype=1 and uitype=14 and
							exists (select 1 from vtiger_field where vtiger_field.tabid = cbfld.tabid and uitype=5)';
                    break;
                }
            }
            $params = array();
        }
        if ($sqlmods == '') {
            $sqlmods = 'SELECT distinct cbfld.tabid,vtiger_tab.name
				FROM vtiger_field as cbfld
				INNER JOIN vtiger_tab on cbfld.tabid = vtiger_tab.tabid
				INNER JOIN vtiger_profile2tab on vtiger_profile2tab.tabid = vtiger_tab.tabid
				WHERE vtiger_tab.presence=0 and vtiger_tab.isentitytype=1 and uitype=14
					and vtiger_profile2tab.profileid in (' . generateQuestionMarks($profileList) . ') and vtiger_profile2tab.permissions=0 and
					exists (select 1 from vtiger_field where vtiger_field.tabid = cbfld.tabid and uitype=5)';
            $params = array($profileList);
        }
    }
    $rsmwd = $adb->pquery($sqlmods, $params);
    $modswithdt = array();
    while ($mod = $adb->fetch_array($rsmwd)) {
        $modswithdt[$mod['tabid']] = $mod['name'];
    }
    uasort($modswithdt, function ($a, $b) {
        return strtolower(getTranslatedString($a, $a)) < strtolower(getTranslatedString($b, $b)) ? -1 : 1;
    });
    return $modswithdt;
}
Ejemplo n.º 12
0
function CheckFieldPermission($fieldname, $module)
{
    global $current_user, $adb;
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    if ($fieldname == '' || $module == '') {
        return "false";
    }
    if ($module == 'Calendar') {
        $tab_id = array(9, 16);
    } else {
        $tab_id = getTabid($module);
    }
    if ($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1) {
        $profileList = getCurrentUserProfileList();
        $sql1 = "SELECT fieldname FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid in(" . generateQuestionMarks($tab_id) . ") AND fieldname=? AND vtiger_field.displaytype IN (1,2,3,4) AND vtiger_profile2field.visible=0 AND vtiger_def_org_field.visible=0 AND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ") and vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid ORDER BY block,sequence";
        $result1 = $adb->pquery($sql1, array($tab_id, $fieldname, $profileList));
        $permission = $adb->num_rows($result1) > 0 ? "true" : "false";
    } else {
        $permission = "true";
    }
    return $permission;
}
Ejemplo n.º 13
0
 function getStdCriteriaByModule($module)
 {
     $adb = PearDatabase::getInstance();
     $tabid = getTabid($module);
     $blockids = $params = $profileList = array();
     $user_privileges_path = 'user_privileges/user_privileges_' . $this->current_user->id . '.php';
     if (file_exists($user_privileges_path)) {
         require $user_privileges_path;
     }
     $module_info = $this->getCustomViewModuleInfo($module);
     if (!isset($this->module_list) || empty($this->module_list)) {
         $this->initListOfModules();
     }
     foreach ($this->module_list[$module] as $key => $blockid) {
         $blockids[] = $blockid;
     }
     if (is_array($blockids)) {
         $blocks_params = implode(",", $blockids);
     } else {
         $blocks_params = $blockids;
     }
     if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
         $sql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid ";
         $sql .= " where vtiger_field.tabid={$tabid} and vtiger_field.block in ({$blocks_params})\n                        and vtiger_field.uitype in (5,6,23,70)";
         $sql .= " and vtiger_field.presence in (0,2) order by vtiger_field.sequence";
     } else {
         $profileList = getCurrentUserProfileList();
         $sql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid inner join  vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid ";
         $sql .= " where vtiger_field.tabid={$tabid} and vtiger_field.block in ({$blocks_params}) and vtiger_field.uitype in (5,6,23,70)";
         $sql .= " and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
         if (count($profileList) > 0) {
             $sql .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")";
             array_push($params, $profileList);
         }
         $sql .= " order by vtiger_field.sequence";
     }
     $result = $adb->pquery($sql, $profileList);
     while ($criteriatyperow = $adb->fetch_array($result)) {
         $fieldtablename = $criteriatyperow["tablename"];
         $fieldcolname = $criteriatyperow["columnname"];
         $fieldlabel = $criteriatyperow["fieldlabel"];
         $fieldname = $criteriatyperow["fieldname"];
         $fieldlabel1 = $fieldlabel;
         $typeofdata = explode("~", $criteriatyperow["typeofdata"]);
         $typeofdata = $typeofdata[0];
         //             $optionvalue = $fieldtablename . ":" . $fieldcolname . ":" . $module . "_" . $fieldlabel1 . ":" . $fieldname . ":" . $typeofdata;
         $optionvalue = $fieldtablename . ":" . $fieldcolname . ":" . $module . "_" . $fieldlabel1 . ":" . $fieldname . ":" . $typeofdata;
         $stdcriteria_list[$optionvalue] = $fieldlabel;
     }
     return $stdcriteria_list;
 }
Ejemplo n.º 14
0
 /**
  * Function to get calendar query for outlookplugin
  * @param   string    $username     -  User name
  * @return  string    $query        -  sql query
  */
 function get_calendarsforol($user_name)
 {
     global $log, $adb, $current_user;
     $log->debug("Entering get_calendarsforol(" . $user_name . ") method ...");
     require_once "modules/Users/Users.php";
     $seed_user = new Users();
     $user_id = $seed_user->retrieve_user_id($user_name);
     $current_user = $seed_user;
     $current_user->retrieve_entity_info($user_id, 'Users');
     require 'user_privileges/user_privileges_' . $current_user->id . '.php';
     require 'user_privileges/sharing_privileges_' . $current_user->id . '.php';
     //get users group ID's
     $gquery = 'SELECT groupid FROM vtiger_users2group WHERE userid=?';
     $gresult = $adb->pquery($gquery, array($user_id));
     for ($j = 0; $j < $adb->num_rows($gresult); $j++) {
         $groupidlist .= "," . $adb->query_result($gresult, $j, 'groupid');
     }
     if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
         $sql1 = "select tablename,columnname from vtiger_field where tabid=9 and tablename <> 'vtiger_recurringevents' and tablename <> 'vtiger_activity_reminder' and vtiger_field.presence in (0,2)";
         $params1 = array();
     } else {
         $profileList = getCurrentUserProfileList();
         $sql1 = "select tablename,columnname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=9 and tablename <> 'vtiger_recurringevents' and tablename <> 'vtiger_activity_reminder' and vtiger_field.displaytype in (1,2,4,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
         $params1 = array();
         if (count($profileList) > 0) {
             $sql1 .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")";
             array_push($params1, $profileList);
         }
     }
     $result1 = $adb->pquery($sql1, $params1);
     for ($i = 0; $i < $adb->num_rows($result1); $i++) {
         $permitted_lists[] = $adb->query_result($result1, $i, 'tablename');
         $permitted_lists[] = $adb->query_result($result1, $i, 'columnname');
         if ($adb->query_result($result1, $i, 'columnname') == "date_start") {
             $permitted_lists[] = 'vtiger_activity';
             $permitted_lists[] = 'time_start';
         }
         if ($adb->query_result($result1, $i, 'columnname') == "due_date") {
             $permitted_lists[] = 'vtiger_activity';
             $permitted_lists[] = 'time_end';
         }
     }
     $permitted_lists = array_chunk($permitted_lists, 2);
     $column_table_lists = array();
     for ($i = 0; $i < count($permitted_lists); $i++) {
         if ($permitted_lists[$i][0] != 'vtiger_activitycf') {
             $column_table_lists[] = implode(".", $permitted_lists[$i]);
         }
     }
     $query = "SELECT vtiger_activity.activityid AS clndrid, " . implode(',', $column_table_lists) . " FROM vtiger_activity \n\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_activity.activityid \n\t\t\t\tLEFT JOIN vtiger_salesmanactivityrel ON vtiger_salesmanactivityrel.activityid=vtiger_activity.activityid \n\t\t\t\tLEFT JOIN vtiger_users ON vtiger_users.id=vtiger_salesmanactivityrel.smid \n\t\t\t\tLEFT JOIN vtiger_cntactivityrel ON vtiger_cntactivityrel.activityid=vtiger_activity.activityid \n\t\t\t\tLEFT JOIN vtiger_contactdetails ON vtiger_contactdetails.contactid=vtiger_cntactivityrel.contactid \n\t\t\t\tLEFT JOIN vtiger_seactivityrel ON vtiger_seactivityrel.activityid = vtiger_activity.activityid \n\t\t\t\tLEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid \n\t\t\t\tWHERE vtiger_crmentity.deleted=0 AND vtiger_activity.activitytype='Meeting' ";
     if (isset($groupidlist)) {
         $query .= " AND (vtiger_users.user_name='" . $user_name . "' OR vtiger_crmentity.smownerid IN (" . substr($groupidlist, 1) . "))";
     } else {
         $query .= " AND vtiger_users.user_name='" . $user_name . "'";
     }
     //crm-now added GROUP BY to prevent the same entry to appear multiple times if assigned to multiple contacts during synchronization with Outlook
     $query .= " GROUP BY clndrid";
     $log->debug("Exiting get_calendarsforol method ...");
     return $query;
 }
Ejemplo n.º 15
0
    //$mass_merge = implode(",",$mass_merge);
} else {
    if ($single_record != "") {
        $mass_merge = $single_record;
    } else {
        die("Record Id is not found, cannot merge the document");
    }
}
//<<<<<<<<<<<<<<<<header for csv and select columns for query>>>>>>>>>>>>>>>>>>>>>>>>
global $current_user;
require 'user_privileges/user_privileges_' . $current_user->id . '.php';
if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || $module == "Users" || $module == "Emails") {
    $query1 = "select vtiger_tab.name,vtiger_field.tablename,vtiger_field.columnname,vtiger_field.fieldlabel from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid where vtiger_field.tabid in (13,4,6) and vtiger_field.uitype <> 61 and block <> 75 and block <> 30 and vtiger_field.presence in (0,2) order by vtiger_field.tablename";
    $params1 = array();
} else {
    $profileList = getCurrentUserProfileList();
    $query1 = "select vtiger_tab.name,vtiger_field.tablename,vtiger_field.columnname,vtiger_field.fieldlabel from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid in (13,4,6) and vtiger_field.uitype <> 61 and block <> 75 and block <> 30 AND vtiger_profile2field.visible=0 AND vtiger_def_org_field.visible=0 AND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ") and vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid order by vtiger_field.tablename";
    $params1 = array($profileList);
    //Postgres 8 fixes
    if ($adb->dbType == "pgsql") {
        $query1 = fixPostgresQuery($query1, $log, 0);
    }
}
$result = $adb->pquery($query1, $params1);
$y = $adb->num_rows($result);
$userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users');
$contactUserNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'usersContacts.first_name', 'last_name' => 'usersContacts.last_name'), 'Users');
$accountUserNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'usersAccounts.first_name', 'last_name' => 'usersAccounts.last_name'), 'Users');
for ($x = 0; $x < $y; $x++) {
    $tablename = $adb->query_result($result, $x, "tablename");
    $columnname = $adb->query_result($result, $x, "columnname");
Ejemplo n.º 16
0
 function insertIntoEntityTable($table_name, $module, $fileid = '')
 {
     global $log;
     global $current_user, $app_strings;
     global $adb;
     $log->debug("Entering PaymentManagement::insertIntoEntityTable(" . $table_name . ", " . $module . ", " . $fileid . ") method ...");
     $value_table = array();
     $insertion_mode = $this->mode;
     //Checkin whether an entry is already is present in the vtiger_table to update
     if ($insertion_mode == 'edit') {
         $tablekey = $this->tab_name_index[$table_name];
         // Make selection on the primary key of the module table to check.
         $check_query = "select {$tablekey} from {$table_name} where {$tablekey}=?";
         $check_result = $adb->pquery($check_query, array($this->id));
         $num_rows = $adb->num_rows($check_result);
         if ($num_rows <= 0) {
             $insertion_mode = '';
         }
     }
     $tabid = getTabid($module);
     if ($insertion_mode == 'edit') {
         $update = array();
         $update_params = array();
         checkFileAccessForInclusion('user_privileges/user_privileges_' . $current_user->id . '.php');
         require 'user_privileges/user_privileges_' . $current_user->id . '.php';
         if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
             $sql = "select * from vtiger_field where tabid in (" . generateQuestionMarks($tabid) . ") and tablename=? and displaytype in (1,3) and presence in (0,2) group by columnname";
             $params = array($tabid, $table_name);
         } else {
             $profileList = getCurrentUserProfileList();
             if (count($profileList) > 0) {
                 $sql = "SELECT *\n\t\t\t  \t\t\tFROM vtiger_field\n\t\t\t  \t\t\tINNER JOIN vtiger_profile2field\n\t\t\t  \t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t  \t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t  \t\t\tAND vtiger_profile2field.visible = 0 AND vtiger_profile2field.readonly = 0\n\t\t\t  \t\t\tAND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")\n\t\t\t  \t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.tablename=? and vtiger_field.displaytype in (1,3) and vtiger_field.presence in (0,2) group by columnname";
                 $params = array($tabid, $profileList, $table_name);
             } else {
                 $sql = "SELECT *\n\t\t\t  \t\t\tFROM vtiger_field\n\t\t\t  \t\t\tINNER JOIN vtiger_profile2field\n\t\t\t  \t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t  \t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t  \t\t\tAND vtiger_profile2field.visible = 0 AND vtiger_profile2field.readonly = 0\n\t\t\t  \t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.tablename=? and vtiger_field.displaytype in (1,3) and vtiger_field.presence in (0,2) group by columnname";
                 $params = array($tabid, $table_name);
             }
         }
     } else {
         $table_index_column = $this->tab_name_index[$table_name];
         if ($table_index_column == 'id' && $table_name == 'vtiger_users') {
             $currentuser_id = $adb->getUniqueID("vtiger_users");
             $this->id = $currentuser_id;
         }
         $columname = $table_index_column;
         $fldvalue = $this->id;
         $column = array($table_index_column);
         $value = array($this->id);
         // vtiger_payment_management のインデックスを登録 (2015/11/26)
         $columname = $table_index_column;
         // tao
         $fldvalue = $this->id;
         // tao
         $value_table[$columname] = $fldvalue;
         // tao
         $sql = "select * from vtiger_field where tabid=? and tablename=? and displaytype in (1,3,4) and vtiger_field.presence in (0,2)";
         $params = array($tabid, $table_name);
     }
     // Attempt to re-use the quer-result to avoid reading for every save operation
     // TODO Need careful analysis on impact ... MEMORY requirement might be more
     static $_privatecache = array();
     $cachekey = "{$insertion_mode}-" . implode(',', $params);
     if (!isset($_privatecache[$cachekey])) {
         $result = $adb->pquery($sql, $params);
         $noofrows = $adb->num_rows($result);
         if (CRMEntity::isBulkSaveMode()) {
             $cacheresult = array();
             for ($i = 0; $i < $noofrows; ++$i) {
                 $cacheresult[] = $adb->fetch_array($result);
             }
             $_privatecache[$cachekey] = $cacheresult;
         }
     } else {
         // Useful when doing bulk save
         $result = $_privatecache[$cachekey];
         $noofrows = count($result);
     }
     for ($i = 0; $i < $noofrows; $i++) {
         $fieldname = $this->resolve_query_result_value($result, $i, "fieldname");
         $columname = $this->resolve_query_result_value($result, $i, "columnname");
         $uitype = $this->resolve_query_result_value($result, $i, "uitype");
         $generatedtype = $this->resolve_query_result_value($result, $i, "generatedtype");
         $typeofdata = $this->resolve_query_result_value($result, $i, "typeofdata");
         $typeofdata_array = explode("~", $typeofdata);
         $datatype = $typeofdata_array[0];
         $ajaxSave = false;
         // uitype == 2
         if ($_REQUEST['file'] == 'DetailViewAjax' && $_REQUEST['ajxaction'] == 'DETAILVIEW' && isset($_REQUEST["fldName"]) && $_REQUEST["fldName"] != $fieldname || $_REQUEST['action'] == 'MassEditSave' && !isset($_REQUEST[$fieldname . "_mass_edit_check"])) {
             $ajaxSave = true;
         }
         if ($uitype == 4 && $insertion_mode != 'edit') {
             $fldvalue = '';
             // Bulk Save Mode: Avoid generation of module sequence number, take care later.
             if (!CRMEntity::isBulkSaveMode()) {
                 $fldvalue = $this->setModuleSeqNumber("increment", $module);
             }
             $this->column_fields[$fieldname] = $fldvalue;
         }
         if (isset($this->column_fields[$fieldname])) {
             if ($uitype == 56) {
                 if ($this->column_fields[$fieldname] == 'on' || $this->column_fields[$fieldname] == 1) {
                     $fldvalue = '1';
                 } else {
                     $fldvalue = '0';
                 }
             } elseif ($uitype == 15 || $uitype == 16) {
                 if ($this->column_fields[$fieldname] == $app_strings['LBL_NOT_ACCESSIBLE']) {
                     //If the value in the request is Not Accessible for a picklist,
                     //the existing value will be replaced instead of Not Accessible value.
                     $sql = "select {$columname} from  {$table_name} where " . $this->tab_name_index[$table_name] . "=?";
                     $res = $adb->pquery($sql, array($this->id));
                     $pick_val = $adb->query_result($res, 0, $columname);
                     $fldvalue = $pick_val;
                 } else {
                     $fldvalue = $this->column_fields[$fieldname];
                 }
             } elseif ($uitype == 33) {
                 if (is_array($this->column_fields[$fieldname])) {
                     $field_list = implode(' |##| ', $this->column_fields[$fieldname]);
                 } else {
                     $field_list = $this->column_fields[$fieldname];
                 }
                 $fldvalue = $field_list;
             } elseif ($uitype == 5 || $uitype == 6 || $uitype == 23) {
                 //Added to avoid function call getDBInsertDateValue in ajax save
                 if (isset($current_user->date_format) && !$ajaxSave) {
                     $fldvalue = getValidDBInsertDateValue($this->column_fields[$fieldname]);
                 } else {
                     $fldvalue = $this->column_fields[$fieldname];
                 }
             } elseif ($uitype == 7) {
                 //strip out the spaces and commas in numbers if given ie., in amounts there may be ,
                 $fldvalue = str_replace(",", "", $this->column_fields[$fieldname]);
                 //trim($this->column_fields[$fieldname],",");
             } elseif ($uitype == 26) {
                 if (empty($this->column_fields[$fieldname])) {
                     $fldvalue = 1;
                     //the documents will stored in default folder
                 } else {
                     $fldvalue = $this->column_fields[$fieldname];
                 }
             } elseif ($uitype == 28) {
                 if ($this->column_fields[$fieldname] == null) {
                     $fileQuery = $adb->pquery("SELECT filename from vtiger_notes WHERE notesid = ?", array($this->id));
                     $fldvalue = null;
                     if (isset($fileQuery)) {
                         $rowCount = $adb->num_rows($fileQuery);
                         if ($rowCount > 0) {
                             $fldvalue = decode_html($adb->query_result($fileQuery, 0, 'filename'));
                         }
                     }
                 } else {
                     $fldvalue = decode_html($this->column_fields[$fieldname]);
                 }
             } elseif ($uitype == 8) {
                 $this->column_fields[$fieldname] = rtrim($this->column_fields[$fieldname], ',');
                 $ids = explode(',', $this->column_fields[$fieldname]);
                 $json = new Zend_Json();
                 $fldvalue = $json->encode($ids);
             } elseif ($uitype == 12) {
                 // Bulk Sae Mode: Consider the FROM email address as specified, if not lookup
                 $fldvalue = $this->column_fields[$fieldname];
                 if (empty($fldvalue)) {
                     $query = "SELECT email1 FROM vtiger_users WHERE id = ?";
                     $res = $adb->pquery($query, array($current_user->id));
                     $rows = $adb->num_rows($res);
                     if ($rows > 0) {
                         $fldvalue = $adb->query_result($res, 0, 'email1');
                     }
                 }
                 // END
             } elseif ($uitype == 72 && !$ajaxSave) {
                 // Some of the currency fields like Unit Price, Totoal , Sub-total - doesn't need currency conversion during save
                 $fldvalue = CurrencyField::convertToDBFormat($this->column_fields[$fieldname], null, true);
             } elseif ($uitype == 71 && !$ajaxSave) {
                 $fldvalue = CurrencyField::convertToDBFormat($this->column_fields[$fieldname]);
             } else {
                 $fldvalue = $this->column_fields[$fieldname];
             }
             if ($uitype != 33 && $uitype != 8) {
                 $fldvalue = from_html($fldvalue, $insertion_mode == 'edit' ? true : false);
             }
         } else {
             $fldvalue = '';
         }
         if ($fldvalue == '') {
             $fldvalue = $this->get_column_value($columname, $fldvalue, $fieldname, $uitype, $datatype);
         }
         // key-value 配列にキーと値の組を登録する
         $value_table[$columname] = $fldvalue;
         // tao
         if ($insertion_mode == 'edit') {
             if ($table_name != 'vtiger_ticketcomments' && $uitype != 4) {
                 array_push($update, $columname . "=?");
                 array_push($update_params, $fldvalue);
             }
         } else {
             array_push($column, $columname);
             array_push($value, $fldvalue);
         }
     }
     if ($insertion_mode == 'edit') {
         // ADDED by tao on 15/12/04 -- begin
         if ($table_name == 'vtiger_payment_management') {
             // 顧客名が指定されていない場合は、カナ名から顧客名を類推する。 */
             $value_table = $this->insertClientName($value_table);
             $update_params = PaymentManagement::generateValues($value_table);
             if ($value_table['accountname'] != '') {
                 $sql = 'update vtiger_crmentityrel set crmid=? where relcrmid=?';
                 $param = array($value_table['accountname'], $this->id);
                 $adb->pquery($sql, $param);
             }
         }
         // ADDED by tao on 15/12/04 -- end
         //Check done by Don. If update is empty the the query fails
         if (count($update) > 0) {
             $sql1 = "update {$table_name} set " . implode(",", $update) . " where " . $this->tab_name_index[$table_name] . "=?";
             array_push($update_params, $this->id);
             $adb->pquery($sql1, $update_params, true);
         }
     } else {
         // Added by 田尾 (tao) on 15/11/25 -- begin
         if ($module == 'PaymentManagement' && $table_name == 'vtiger_payment_management') {
             $value_table = $this->insertClientName($value_table);
             if ($value_table['accountname'] != '') {
                 $this->save_related_module('Account', $value_table['accountname'], 'PaymentManagement', $value_table['payment_management_id']);
             }
         }
         $value = PaymentManagement::generateValues($value_table);
         // Added by 田尾 (tao) on 15/11/25 -- end
         $sql1 = "insert into {$table_name}(" . implode(",", $column) . ") values(" . generateQuestionMarks($value) . ")";
         $adb->pquery($sql1, $value);
     }
     $log->debug("Exting PaymentManagement::insertIntoEntityTable(" . $table_name . ", " . $module . ", " . $fileid . ") method ...");
 }
Ejemplo n.º 17
0
 /** Function to insert values in the specifed table for the specified module
  * @param $table_name -- table name:: Type varchar
  * @param $module -- module:: Type varchar
  */
 function insertIntoEntityTable($table_name, $module, $fileid = '')
 {
     global $log;
     global $current_user, $app_strings;
     $log->info("function insertIntoEntityTable " . $module . ' vtiger_table name ' . $table_name);
     global $adb;
     $insertion_mode = $this->mode;
     //Checkin whether an entry is already is present in the vtiger_table to update
     if ($insertion_mode == 'edit') {
         $tablekey = $this->tab_name_index[$table_name];
         // Make selection on the primary key of the module table to check.
         $check_query = "select {$tablekey} from {$table_name} where {$tablekey}=?";
         $check_result = $adb->pquery($check_query, array($this->id));
         $num_rows = $adb->num_rows($check_result);
         if ($num_rows <= 0) {
             $insertion_mode = '';
         }
     }
     $tabid = getTabid($module);
     if ($module == 'Calendar' && $this->column_fields["activitytype"] != null && $this->column_fields["activitytype"] != 'Task') {
         $tabid = getTabid('Events');
     }
     if ($insertion_mode == 'edit') {
         $update = array();
         $update_params = array();
         require 'user_privileges/user_privileges_' . $current_user->id . '.php';
         if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
             $sql = "select * from vtiger_field where tabid in (" . generateQuestionMarks($tabid) . ") and tablename=? and displaytype in (1,3) and presence in (0,2) group by columnname";
             $params = array($tabid, $table_name);
         } else {
             $profileList = getCurrentUserProfileList();
             if (count($profileList) > 0) {
                 $sql = "SELECT *\n\t\t\t  \t\t\tFROM vtiger_field\n\t\t\t  \t\t\tINNER JOIN vtiger_profile2field\n\t\t\t  \t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t  \t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t  \t\t\tAND vtiger_profile2field.visible = 0 \n\t\t\t  \t\t\tAND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")\n\t\t\t  \t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.tablename=? and vtiger_field.displaytype in (1,3) and vtiger_field.presence in (0,2) group by columnname";
                 $params = array($tabid, $profileList, $table_name);
             } else {
                 $sql = "SELECT *\n\t\t\t  \t\t\tFROM vtiger_field\n\t\t\t  \t\t\tINNER JOIN vtiger_profile2field\n\t\t\t  \t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t  \t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t  \t\t\tAND vtiger_profile2field.visible = 0 \n\t\t\t  \t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.tablename=? and vtiger_field.displaytype in (1,3) and vtiger_field.presence in (0,2) group by columnname";
                 $params = array($tabid, $table_name);
             }
         }
     } else {
         $table_index_column = $this->tab_name_index[$table_name];
         if ($table_index_column == 'id' && $table_name == 'vtiger_users') {
             $currentuser_id = $adb->getUniqueID("vtiger_users");
             $this->id = $currentuser_id;
         }
         $column = array($table_index_column);
         $value = array($this->id);
         $sql = "select * from vtiger_field where tabid=? and tablename=? and displaytype in (1,3,4) and vtiger_field.presence in (0,2)";
         $params = array($tabid, $table_name);
     }
     $result = $adb->pquery($sql, $params);
     $noofrows = $adb->num_rows($result);
     for ($i = 0; $i < $noofrows; $i++) {
         $fieldname = $adb->query_result($result, $i, "fieldname");
         $columname = $adb->query_result($result, $i, "columnname");
         $uitype = $adb->query_result($result, $i, "uitype");
         $generatedtype = $adb->query_result($result, $i, "generatedtype");
         $typeofdata = $adb->query_result($result, $i, "typeofdata");
         $typeofdata_array = explode("~", $typeofdata);
         $datatype = $typeofdata_array[0];
         if ($uitype == 4 && $insertion_mode != 'edit') {
             $this->column_fields[$fieldname] = $this->setModuleSeqNumber("increment", $module);
             $fldvalue = $this->column_fields[$fieldname];
         }
         if (isset($this->column_fields[$fieldname])) {
             if ($uitype == 56) {
                 if ($this->column_fields[$fieldname] == 'on' || $this->column_fields[$fieldname] == 1) {
                     $fldvalue = '1';
                 } else {
                     $fldvalue = '0';
                 }
             } elseif ($uitype == 15 || $uitype == 16) {
                 if ($this->column_fields[$fieldname] == $app_strings['LBL_NOT_ACCESSIBLE']) {
                     //If the value in the request is Not Accessible for a picklist, the existing value will be replaced instead of Not Accessible value.
                     $sql = "select {$columname} from  {$table_name} where " . $this->tab_name_index[$table_name] . "=?";
                     $res = $adb->pquery($sql, array($this->id));
                     $pick_val = $adb->query_result($res, 0, $columname);
                     $fldvalue = $pick_val;
                 } else {
                     $fldvalue = $this->column_fields[$fieldname];
                 }
             } elseif ($uitype == 33) {
                 if (is_array($this->column_fields[$fieldname])) {
                     $field_list = implode(' |##| ', $this->column_fields[$fieldname]);
                 } else {
                     $field_list = $this->column_fields[$fieldname];
                 }
                 $fldvalue = $field_list;
             } elseif ($uitype == 5 || $uitype == 6 || $uitype == 23) {
                 if ($_REQUEST['action'] == 'Import') {
                     $fldvalue = $this->column_fields[$fieldname];
                 } else {
                     //Added to avoid function call getDBInsertDateValue in ajax save
                     if (isset($current_user->date_format)) {
                         $fldvalue = getValidDBInsertDateValue($this->column_fields[$fieldname]);
                     } else {
                         $fldvalue = $this->column_fields[$fieldname];
                     }
                 }
             } elseif ($uitype == 7) {
                 //strip out the spaces and commas in numbers if given ie., in amounts there may be ,
                 $fldvalue = str_replace(",", "", $this->column_fields[$fieldname]);
                 //trim($this->column_fields[$fieldname],",");
             } elseif ($uitype == 26) {
                 if (empty($this->column_fields[$fieldname])) {
                     $fldvalue = 1;
                     //the documents will stored in default folder
                 } else {
                     $fldvalue = $this->column_fields[$fieldname];
                 }
             } elseif ($uitype == 28) {
                 if ($this->column_fields[$fieldname] == null) {
                     $fileQuery = $adb->pquery("SELECT filename from vtiger_notes WHERE notesid = ?", array($this->id));
                     $fldvalue = null;
                     if (isset($fileQuery)) {
                         $rowCount = $adb->num_rows($fileQuery);
                         if ($rowCount > 0) {
                             $fldvalue = $adb->query_result($fileQuery, 0, 'filename');
                         }
                     }
                 } else {
                     $fldvalue = $this->column_fields[$fieldname];
                 }
             } elseif ($uitype == 8) {
                 $this->column_fields[$fieldname] = rtrim($this->column_fields[$fieldname], ',');
                 $ids = explode(',', $this->column_fields[$fieldname]);
                 $json = new Zend_Json();
                 $fldvalue = $json->encode($ids);
             } elseif ($uitype == 12) {
                 $query = "SELECT email1 FROM vtiger_users WHERE id = ?";
                 $res = $adb->pquery($query, array($current_user->id));
                 $rows = $adb->num_rows($res);
                 if ($rows > 0) {
                     $fldvalue = $adb->query_result($res, 0, 'email1');
                 }
             } elseif ($uitype == 71 && $generatedtype == 2) {
                 // Convert currency to base currency value before saving for custom fields of type currency
                 $currency_id = $current_user->currency_id;
                 $curSymCrate = getCurrencySymbolandCRate($currency_id);
                 $fldvalue = convertToDollar($this->column_fields[$fieldname], $curSymCrate['rate']);
             } else {
                 $fldvalue = $this->column_fields[$fieldname];
             }
             if ($uitype != 33 && $uitype != 8) {
                 $fldvalue = from_html($fldvalue, $insertion_mode == 'edit' ? true : false);
             }
         } else {
             $fldvalue = '';
         }
         if ($fldvalue == '') {
             $fldvalue = $this->get_column_value($columname, $fldvalue, $fieldname, $uitype, $datatype);
         }
         if ($insertion_mode == 'edit') {
             if ($table_name != 'vtiger_ticketcomments' && $uitype != 4) {
                 array_push($update, $columname . "=?");
                 array_push($update_params, $fldvalue);
             }
         } else {
             array_push($column, $columname);
             array_push($value, $fldvalue);
         }
     }
     if ($insertion_mode == 'edit') {
         if ($_REQUEST['module'] == 'Potentials') {
             $dbquery = 'select sales_stage from vtiger_potential where potentialid = ?';
             $sales_stage = $adb->query_result($adb->pquery($dbquery, array($this->id)), 0, 'sales_stage');
             if ($sales_stage != $_REQUEST['sales_stage'] && $_REQUEST['sales_stage'] != '') {
                 $date_var = date('YmdHis');
                 $closingdate = $_REQUEST['ajxaction'] == 'DETAILVIEW' ? $this->column_fields['closingdate'] : getDBInsertDateValue($this->column_fields['closingdate']);
                 $sql = "insert into vtiger_potstagehistory values(?,?,?,?,?,?,?,?)";
                 $params = array('', $this->id, $this->column_fields['amount'], decode_html($sales_stage), $this->column_fields['probability'], 0, $adb->formatDate($closingdate, true), $adb->formatDate($date_var, true));
                 $adb->pquery($sql, $params);
             }
         } elseif ($_REQUEST['module'] == 'PurchaseOrder' || $_REQUEST['module'] == 'SalesOrder' || $_REQUEST['module'] == 'Quotes' || $_REQUEST['module'] == 'Invoice') {
             //added to update the history for PO, SO, Quotes and Invoice
             $history_field_array = array("PurchaseOrder" => "postatus", "SalesOrder" => "sostatus", "Quotes" => "quotestage", "Invoice" => "invoicestatus");
             $inventory_module = $_REQUEST['module'];
             if ($_REQUEST['ajxaction'] == 'DETAILVIEW') {
                 if ($inventory_module == "PurchaseOrder") {
                     $relatedname = getVendorName($this->column_fields['vendor_id']);
                 } else {
                     $relatedname = getAccountName($this->column_fields['account_id']);
                 }
                 $total = $this->column_fields['hdnGrandTotal'];
             } else {
                 if ($inventory_module == "PurchaseOrder") {
                     $relatedname = $_REQUEST["vendor_name"];
                 } else {
                     $relatedname = $_REQUEST["account_name"];
                 }
                 $total = $_REQUEST['total'];
             }
             if ($this->column_fields["{$history_field_array[$inventory_module]}"] == $app_strings['LBL_NOT_ACCESSIBLE']) {
                 //If the value in the request is Not Accessible for a picklist, the existing value will be replaced instead of Not Accessible value.
                 $his_col = $history_field_array[$inventory_module];
                 $his_sql = "select {$his_col} from  {$this->table_name} where " . $this->table_index . "=?";
                 $his_res = $adb->pquery($his_sql, array($this->id));
                 $status_value = $adb->query_result($his_res, 0, $his_col);
                 $stat_value = $status_value;
             } else {
                 $stat_value = $this->column_fields["{$history_field_array[$inventory_module]}"];
             }
             $oldvalue = getSingleFieldValue($this->table_name, $history_field_array[$inventory_module], $this->table_index, $this->id);
             if ($this->column_fields["{$history_field_array[$inventory_module]}"] != '' && $oldvalue != $stat_value) {
                 addInventoryHistory($inventory_module, $this->id, $relatedname, $total, $stat_value);
             }
         }
         //Check done by Don. If update is empty the the query fails
         if (count($update) > 0) {
             $sql1 = "update {$table_name} set " . implode(",", $update) . " where " . $this->tab_name_index[$table_name] . "=?";
             array_push($update_params, $this->id);
             $adb->pquery($sql1, $update_params);
         }
     } else {
         $sql1 = "insert into {$table_name}(" . implode(",", $column) . ") values(" . generateQuestionMarks($value) . ")";
         $adb->pquery($sql1, $value);
     }
 }
Ejemplo n.º 18
0
function getCalendarCustomFields($tabid, $mode = 'edit', $col_fields = '')
{
    global $adb, $log, $current_user;
    $log->debug("Entering getCalendarCustomFields({$tabid}, {$mode}, {$col_fields})");
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    $isduplicate = vtlib_purify($_REQUEST['isDuplicate']);
    $calmode = vtlib_purify($_REQUEST['action']);
    $block = getBlockId($tabid, "LBL_CUSTOM_INFORMATION");
    $custparams = array($block, $tabid);
    if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
        $custquery = "select * from vtiger_field where block=? AND vtiger_field.tabid=? ORDER BY fieldid";
    } else {
        $profileList = getCurrentUserProfileList();
        $custquery = "SELECT vtiger_field.* FROM vtiger_field" . " INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid" . " INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid" . " WHERE vtiger_field.block=? AND vtiger_field.tabid=? AND vtiger_profile2field.visible=0" . " AND vtiger_def_org_field.visible=0 AND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")";
        if ($mode == 'edit') {
            $custquery .= "  AND vtiger_profile2field.readonly = 0";
        }
        $custquery .= " GROUP BY vtiger_field.fieldid";
        array_push($custparams, $profileList);
    }
    $custresult = $adb->pquery($custquery, $custparams);
    $custFldArray = array();
    $noofrows = $adb->num_rows($custresult);
    for ($i = 0; $i < $noofrows; $i++) {
        $fieldname = $adb->query_result($custresult, $i, "fieldname");
        $fieldlabel = $adb->query_result($custresult, $i, "fieldlabel");
        $columnName = $adb->query_result($custresult, $i, "columnname");
        $uitype = $adb->query_result($custresult, $i, "uitype");
        $maxlength = $adb->query_result($custresult, $i, "maximumlength");
        $generatedtype = $adb->query_result($custresult, $i, "generatedtype");
        $typeofdata = $adb->query_result($custresult, $i, "typeofdata");
        $defaultvalue = $adb->query_result($custresult, $i, "defaultvalue");
        if (empty($col_fields[$fieldname]) && $mode != 'detail_view' && !$isduplicate && $calmode != 'EventEditView' && $calmode != 'EditView') {
            $col_fields[$fieldname] = $defaultvalue;
        }
        if ($mode == 'edit') {
            $custfld = getOutputHtml($uitype, $fieldname, $fieldlabel, $maxlength, $col_fields, $generatedtype, 'Calendar', $mode, $typeofdata);
        }
        if ($mode == 'detail_view') {
            $custfld = getDetailViewOutputHtml($uitype, $fieldname, $fieldlabel, $col_fields, $generatedtype, $tabid);
        }
        $custFldArray[] = $custfld;
    }
    $log->debug("Exiting getCalendarCustomFields()");
    return $custFldArray;
}
Ejemplo n.º 19
0
 private function retrieveMetaForBlock($block)
 {
     global $adb;
     $tabid = $this->getTabId();
     require 'user_privileges/user_privileges_' . $this->user->id . '.php';
     if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
         $sql = "select *, '0' as readonly from vtiger_field where tabid =? and block in (" . generateQuestionMarks($block) . ") and displaytype in (1,2,3,4)";
         $params = array($tabid, $block);
     } else {
         $profileList = getCurrentUserProfileList();
         if (count($profileList) > 0) {
             $sql = "SELECT vtiger_field.*, vtiger_profile2field.readonly\n\t\t\t\t\t\tFROM vtiger_field\n\t\t\t\t\t\tINNER JOIN vtiger_profile2field\n\t\t\t\t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t\t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t\t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t\t\t\tWHERE vtiger_field.tabid =? AND vtiger_profile2field.visible = 0 \n\t\t\t\t\t\tAND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")\n\t\t\t\t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.block in (" . generateQuestionMarks($block) . ") and vtiger_field.displaytype in (1,2,3,4) and vtiger_field.presence in (0,2) group by columnname";
             $params = array($tabid, $profileList, $block);
         } else {
             $sql = "SELECT vtiger_field.*, vtiger_profile2field.readonly\n\t\t\t\t\t\tFROM vtiger_field\n\t\t\t\t\t\tINNER JOIN vtiger_profile2field\n\t\t\t\t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t\t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t\t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t\t\t\tWHERE vtiger_field.tabid=? \n\t\t\t\t\t\tAND vtiger_profile2field.visible = 0 \n\t\t\t\t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.block in (" . generateQuestionMarks($block) . ") and vtiger_field.displaytype in (1,2,3,4) and vtiger_field.presence in (0,2) group by columnname";
             $params = array($tabid, $block);
         }
     }
     // Bulk Save Mode: Group by is not required!?
     if (CRMEntity::isBulkSaveMode()) {
         $sql = preg_replace("/group by [^ ]*/", " ", $sql);
     }
     // END
     $result = $adb->pquery($sql, $params);
     $noofrows = $adb->num_rows($result);
     $referenceArray = array();
     $knownFieldArray = array();
     for ($i = 0; $i < $noofrows; $i++) {
         $fieldname = $adb->query_result($result, $i, "fieldname");
         if (strcasecmp($fieldname, 'imagename') === 0) {
             continue;
         }
         $webserviceField = WebserviceField::fromQueryResult($adb, $result, $i);
         $this->moduleFields[$webserviceField->getFieldName()] = $webserviceField;
     }
 }
Ejemplo n.º 20
0
 /** Function to get field columns based on profile
  *  @ param $module : Type string
  *  returns permitted fields in array format
  */
 function getaccesfield($module)
 {
     $current_user = vglobal('current_user');
     $adb = PearDatabase::getInstance();
     $access_fields = array();
     $profileList = getCurrentUserProfileList();
     $query = "select vtiger_field.fieldname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where";
     $params = array();
     if ($module == "Calendar") {
         if (count($profileList) > 0) {
             $query .= " vtiger_field.tabid in (9,16) and vtiger_field.displaytype in (1,2,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0\n\t\t\t\t\t\t\t\tand vtiger_field.presence IN (0,2) and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ") group by vtiger_field.fieldid order by block,sequence";
             array_push($params, $profileList);
         } else {
             $query .= " vtiger_field.tabid in (9,16) and vtiger_field.displaytype in (1,2,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0\n\t\t\t\t\t\t\t\tand vtiger_field.presence IN (0,2) group by vtiger_field.fieldid order by block,sequence";
         }
     } else {
         array_push($params, $module);
         if (count($profileList) > 0) {
             $query .= " vtiger_field.tabid in (select tabid from vtiger_tab where vtiger_tab.name in (?)) and vtiger_field.displaytype in (1,2,3,5) and vtiger_profile2field.visible=0\n\t\t\t\t\t\t\t\tand vtiger_field.presence IN (0,2) and vtiger_def_org_field.visible=0 and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ") group by vtiger_field.fieldid order by block,sequence";
             array_push($params, $profileList);
         } else {
             $query .= " vtiger_field.tabid in (select tabid from vtiger_tab where vtiger_tab.name in (?)) and vtiger_field.displaytype in (1,2,3,5) and vtiger_profile2field.visible=0\n\t\t\t\t\t\t\t\tand vtiger_field.presence IN (0,2) and vtiger_def_org_field.visible=0 group by vtiger_field.fieldid order by block,sequence";
         }
     }
     $result = $adb->pquery($query, $params);
     while ($collistrow = $adb->fetch_array($result)) {
         $access_fields[] = $collistrow["fieldname"];
     }
     //added to include ticketid for Reports module in select columnlist for all users
     if ($module == "HelpDesk") {
         $access_fields[] = "ticketid";
     }
     return $access_fields;
 }
Ejemplo n.º 21
0
/**
 * This function is used to get the Quick create form vtiger_field parameters for a given module.
 * Param $module - module name
 * returns the value in array format
 */
function QuickCreate($module)
{
    global $log;
    $log->debug("Entering QuickCreate(" . $module . ") method ...");
    global $adb;
    global $current_user;
    global $mod_strings;
    $tabid = getTabid($module);
    //Adding Security Check
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
        $quickcreate_query = "select * from vtiger_field where quickcreate in (0,2) and tabid = ? and vtiger_field.presence in (0,2) and displaytype != 2 order by quickcreatesequence";
        $params = array($tabid);
    } else {
        $profileList = getCurrentUserProfileList();
        $quickcreate_query = "SELECT vtiger_field.* FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=? AND quickcreate in (0,2) AND vtiger_profile2field.visible=0 AND vtiger_profile2field.readonly = 0 AND vtiger_def_org_field.visible=0  AND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ") and vtiger_field.presence in (0,2) and displaytype != 2 GROUP BY vtiger_field.fieldid ORDER BY quickcreatesequence";
        $params = array($tabid, $profileList);
        //Postgres 8 fixes
        if ($adb->dbType == "pgsql") {
            $quickcreate_query = fixPostgresQuery($quickcreate_query, $log, 0);
        }
    }
    $category = getParentTab();
    $result = $adb->pquery($quickcreate_query, $params);
    $noofrows = $adb->num_rows($result);
    $fieldName_array = array();
    for ($i = 0; $i < $noofrows; $i++) {
        $fieldtablename = $adb->query_result($result, $i, 'tablename');
        $uitype = $adb->query_result($result, $i, "uitype");
        $fieldname = $adb->query_result($result, $i, "fieldname");
        $fieldlabel = $adb->query_result($result, $i, "fieldlabel");
        $maxlength = $adb->query_result($result, $i, "maximumlength");
        $generatedtype = $adb->query_result($result, $i, "generatedtype");
        $typeofdata = $adb->query_result($result, $i, "typeofdata");
        $defaultvalue = $adb->query_result($result, $i, "defaultvalue");
        $col_fields[$fieldname] = $defaultvalue;
        //to get validationdata
        $fldLabel_array = array();
        $fldLabel_array[getTranslatedString($fieldlabel)] = $typeofdata;
        $fieldName_array[$fieldname] = $fldLabel_array;
        // These fields should not be shown in the UI as they are already shown as part of other fields, but are required for validation.
        if ($fieldname == 'time_start' || $fieldname == 'time_end') {
            continue;
        }
        $custfld = getOutputHtml($uitype, $fieldname, $fieldlabel, $maxlength, $col_fields, $generatedtype, $module, '', $typeofdata);
        $qcreate_arr[] = $custfld;
    }
    for ($i = 0, $j = 0; $i < count($qcreate_arr); $i = $i + 2, $j++) {
        $key1 = $qcreate_arr[$i];
        if (is_array($qcreate_arr[$i + 1])) {
            $key2 = $qcreate_arr[$i + 1];
        } else {
            $key2 = array();
        }
        $return_data[$j] = array(0 => $key1, 1 => $key2);
    }
    $form_data['form'] = $return_data;
    $form_data['data'] = $fieldName_array;
    $log->debug("Exiting QuickCreate method ..." . print_r($form_data, true));
    return $form_data;
}
Ejemplo n.º 22
0
 /** Function to get the Contacts associated with the particular User Name.
 *  @param varchar $user_name - User Name
 *  Returns query
 */
 function get_contactsforol($user_name)
 {
     global $log, $adb, $current_user;
     require_once "modules/Users/Users.php";
     $seed_user = new Users();
     $user_id = $seed_user->retrieve_user_id($user_name);
     $current_user = $seed_user;
     $current_user->retrieve_entity_info($user_id, 'Users');
     require 'user_privileges/user_privileges_' . $current_user->id . '.php';
     require 'user_privileges/sharing_privileges_' . $current_user->id . '.php';
     if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
         $sql1 = "select tablename,columnname from vtiger_field where tabid=4 and vtiger_field.presence in (0,2)";
         $params1 = array();
     } else {
         $profileList = getCurrentUserProfileList();
         $sql1 = "select tablename,columnname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=4 and vtiger_field.displaytype in (1,2,4,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
         $params1 = array();
         if (count($profileList) > 0) {
             $sql1 .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")";
             array_push($params1, $profileList);
         }
     }
     $result1 = $adb->pquery($sql1, $params1);
     for ($i = 0; $i < $adb->num_rows($result1); $i++) {
         $permitted_lists[] = $adb->query_result($result1, $i, 'tablename');
         $permitted_lists[] = $adb->query_result($result1, $i, 'columnname');
         if ($adb->query_result($result1, $i, 'columnname') == "accountid") {
             $permitted_lists[] = 'vtiger_account';
             $permitted_lists[] = 'accountname';
         }
     }
     $permitted_lists = array_chunk($permitted_lists, 2);
     $column_table_lists = array();
     for ($i = 0; $i < count($permitted_lists); $i++) {
         $column_table_lists[] = implode(".", $permitted_lists[$i]);
     }
     $log->debug("Entering get_contactsforol(" . $user_name . ") method ...");
     $query = "select vtiger_contactdetails.contactid as id, " . implode(',', $column_table_lists) . " from vtiger_contactdetails\n\t\tinner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid\n\t\tinner join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid\n\t\tleft join vtiger_customerdetails on vtiger_customerdetails.customerid=vtiger_contactdetails.contactid\n\t\tleft join vtiger_account on vtiger_account.accountid=vtiger_contactdetails.accountid\n\t\tleft join vtiger_contactaddress on vtiger_contactaddress.contactaddressid=vtiger_contactdetails.contactid\n\t\tleft join vtiger_contactsubdetails on vtiger_contactsubdetails.contactsubscriptionid = vtiger_contactdetails.contactid\n\t\tleft join vtiger_contactscf on vtiger_contactscf.contactid = vtiger_contactdetails.contactid\n\t\tleft join vtiger_campaigncontrel on vtiger_contactdetails.contactid = vtiger_campaigncontrel.contactid\n\t\tleft join vtiger_campaignrelstatus on vtiger_campaignrelstatus.campaignrelstatusid = vtiger_campaigncontrel.campaignrelstatusid\n\t\tLEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid\n\t\twhere vtiger_crmentity.deleted=0 and vtiger_users.user_name='" . $user_name . "'";
     $log->debug("Exiting get_contactsforol method ...");
     return $query;
 }
Ejemplo n.º 23
0
function UpdateClndr($username, $session, $clndrdtls)
{
    if (!validateSession($username, $session)) {
        return null;
    }
    global $current_user;
    global $adb, $log;
    require_once 'modules/Users/Users.php';
    require_once 'modules/Calendar/Activity.php';
    $seed_user = new Users();
    $user_id = $seed_user->retrieve_user_id($username);
    $current_user = $seed_user;
    $current_user->retrieve_entity_info($user_id, "Users");
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    require 'user_privileges/sharing_privileges_' . $current_user->id . '.php';
    if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
        $sql1 = "select fieldname,columnname from vtiger_field where tabid=16 and vtiger_field.presence in (0,2)";
        $params1 = array();
    } else {
        $profileList = getCurrentUserProfileList();
        $sql1 = "select fieldname,columnname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=16 and vtiger_field.displaytype in (1,2,4,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
        $params1 = array();
        if (count($profileList) > 0) {
            $sql1 .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")";
            array_push($params1, $profileList);
        }
    }
    $result1 = $adb->pquery($sql1, $params1);
    for ($i = 0; $i < $adb->num_rows($result1); $i++) {
        $permitted_lists[] = $adb->query_result($result1, $i, 'fieldname');
    }
    $clndr = new Activity();
    foreach ($clndrdtls as $clndrow) {
        if (isset($clndrow)) {
            $astartdtm = explode(" ", $clndrow["startdate"]);
            $aduedtm = explode(" ", $clndrow["duedate"]);
            $atimestart = explode(":", trim($astartdtm[1]));
            $atimedue = explode(":", trim($aduedtm[1]));
            $stimestart = $atimestart[0] . ":" . $atimestart[1];
            $stimeend = $atimedue[0] . ":" . $atimedue[1];
            /*if( $diff=@get_time_difference($stimestart, $stimeend) )
            		{
            			$stimeduehr = sprintf('%02d',$diff['hours']);
            			$stimeduemin = sprintf('%02d',$diff['minutes']);
            		}*/
            $clndr->retrieve_entity_info($clndrow["id"], "Calendar");
            $clndr->column_fields[subject] = in_array('subject', $permitted_lists) ? $clndrow["subject"] : "";
            $clndr->column_fields[date_start] = in_array('date_start', $permitted_lists) ? getDisplayDate(trim($astartdtm[0])) : "";
            $clndr->column_fields[due_date] = in_array('due_date', $permitted_lists) ? getDisplayDate(trim($aduedtm[0])) : "";
            $clndr->column_fields[time_start] = in_array('time_start', $permitted_lists) ? $stimestart : "";
            $clndr->column_fields[time_end] = in_array('time_end', $permitted_lists) ? $stimeend : "";
            //$clndr->column_fields[duration_hours]= in_array('duration_hours',$permitted_lists) ? $stimeduehr : "";
            //$clndr->column_fields[duration_minutes]= in_array('duration_minutes',$permitted_lists) ? $stimeduemin : "";
            $clndr->column_fields[location] = in_array('location', $permitted_lists) ? $clndrow["location"] : "";
            $clndr->column_fields[description] = in_array('description', $permitted_lists) ? $clndrow["description"] : "";
            $clndr->column_fields[activitytype] = "Meeting";
            $clndr->column_fields[assigned_user_id] = in_array('assigned_user_id', $permitted_lists) ? $user_id : "";
            $clndr->id = $clndrow["id"];
            $clndr->mode = "edit";
            $clndr->save("Calendar");
        }
    }
    return $clndr->id;
}
Ejemplo n.º 24
0
 /** Function to form the HTML for columns to total
  *  This function formulates the HTML format of the
  *  vtiger_fields along with four checkboxes
  *  It returns the HTML of the vtiger_fields along with the check boxes
  */
 function sgetColumnstoTotalHTML($module)
 {
     //retreive the vtiger_tabid
     global $adb;
     global $log;
     global $current_user;
     require 'user_privileges/user_privileges_' . $current_user->id . '.php';
     $tabid = getTabid($module);
     $escapedchars = array('__SUM', '__AVG', '__MIN', '__MAX');
     $sparams = array($tabid);
     if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
         $ssql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid where vtiger_field.uitype != 50 and vtiger_field.tabid=? and vtiger_field.displaytype in (1,2,3) and vtiger_field.presence in (0,2) ";
     } else {
         $profileList = getCurrentUserProfileList();
         $ssql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid  where vtiger_field.uitype != 50 and vtiger_field.tabid=? and vtiger_field.displaytype in (1,2,3) and vtiger_def_org_field.visible=0 and vtiger_profile2field.visible=0 and vtiger_field.presence in (0,2)";
         if (count($profileList) > 0) {
             $ssql .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")";
             array_push($sparams, $profileList);
         }
     }
     //Added to avoid display the Related fields (Account name,Vandor name,product name, etc) in Report Calculations(SUM,AVG..)
     switch ($tabid) {
         case 2:
             //Potentials
             //ie. Campaign name will not displayed in Potential's report calcullation
             $ssql .= " and vtiger_field.fieldname not in ('campaignid')";
             break;
         case 4:
             //Contacts
             $ssql .= " and vtiger_field.fieldname not in ('account_id')";
             break;
         case 6:
             //Accounts
             $ssql .= " and vtiger_field.fieldname not in ('account_id')";
             break;
         case 9:
             //Calandar
             $ssql .= " and vtiger_field.fieldname not in ('parent_id','contact_id')";
             break;
         case 13:
             //Trouble tickets(HelpDesk)
             $ssql .= " and vtiger_field.fieldname not in ('parent_id','product_id')";
             break;
         case 14:
             //Products
             $ssql .= " and vtiger_field.fieldname not in ('vendor_id','product_id')";
             break;
         case 20:
             //Quotes
             $ssql .= " and vtiger_field.fieldname not in ('potential_id','assigned_user_id1','account_id','currency_id')";
             break;
         case 21:
             //Purchase Order
             $ssql .= " and vtiger_field.fieldname not in ('contact_id','vendor_id','currency_id')";
             break;
         case 22:
             //SalesOrder
             $ssql .= " and vtiger_field.fieldname not in ('potential_id','account_id','contact_id','quote_id','currency_id')";
             break;
         case 23:
             //Invoice
             $ssql .= " and vtiger_field.fieldname not in ('salesorder_id','contact_id','account_id','currency_id')";
             break;
         case 26:
             //Campaigns
             $ssql .= " and vtiger_field.fieldname not in ('product_id')";
             break;
     }
     $ssql .= " order by sequence";
     $result = $adb->pquery($ssql, $sparams);
     $columntototalrow = $adb->fetch_array($result);
     $options_list = array();
     do {
         $typeofdata = explode("~", $columntototalrow["typeofdata"]);
         if ($typeofdata[0] == "N" || $typeofdata[0] == "I" || $typeofdata[0] == "NN" && !empty($typeofdata[2])) {
             $options = array();
             if (isset($this->columnssummary)) {
                 $selectedcolumn = "";
                 $selectedcolumn1 = "";
                 for ($i = 0; $i < count($this->columnssummary); $i++) {
                     $selectedcolumnarray = explode(":", $this->columnssummary[$i]);
                     $selectedcolumn = $selectedcolumnarray[1] . ":" . $selectedcolumnarray[2] . ":" . str_replace($escapedchars, "", $selectedcolumnarray[3]);
                     if ($selectedcolumn != $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . str_replace(" ", "__", $columntototalrow['fieldlabel'])) {
                         $selectedcolumn = "";
                     } else {
                         $selectedcolumn1[$selectedcolumnarray[4]] = $this->columnssummary[$i];
                     }
                 }
                 if (isset($_REQUEST["record"]) && $_REQUEST["record"] != '') {
                     $options['label'][] = getTranslatedString($columntototalrow['tablabel'], $columntototalrow['tablabel']) . ' -' . getTranslatedString($columntototalrow['fieldlabel'], $columntototalrow['tablabel']);
                 }
                 $columntototalrow['fieldlabel'] = str_replace(" ", "__", $columntototalrow['fieldlabel']);
                 $options[] = getTranslatedString($columntototalrow['tablabel'], $columntototalrow['tablabel']) . ' - ' . getTranslatedString($columntototalrow['fieldlabel'], $columntototalrow['tablabel']);
                 if ($selectedcolumn1[2] == "cb:" . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . "__SUM:2") {
                     $options[] = '<input checked name="cb:' . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . '__SUM:2" type="checkbox" value="">';
                 } else {
                     $options[] = '<input name="cb:' . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . '__SUM:2" type="checkbox" value="">';
                 }
                 if ($selectedcolumn1[3] == "cb:" . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . "__AVG:3") {
                     $options[] = '<input checked name="cb:' . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . '__AVG:3" type="checkbox" value="">';
                 } else {
                     $options[] = '<input name="cb:' . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . '__AVG:3" type="checkbox" value="">';
                 }
                 if ($selectedcolumn1[4] == "cb:" . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . "__MIN:4") {
                     $options[] = '<input checked name="cb:' . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . '__MIN:4" type="checkbox" value="">';
                 } else {
                     $options[] = '<input name="cb:' . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . '__MIN:4" type="checkbox" value="">';
                 }
                 if ($selectedcolumn1[5] == "cb:" . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . "__MAX:5") {
                     $options[] = '<input checked name="cb:' . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . '__MAX:5" type="checkbox" value="">';
                 } else {
                     $options[] = '<input name="cb:' . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . '__MAX:5" type="checkbox" value="">';
                 }
             } else {
                 $options[] = getTranslatedString($columntototalrow['tablabel'], $columntototalrow['tablabel']) . ' - ' . getTranslatedString($columntototalrow['fieldlabel'], $columntototalrow['tablabel']);
                 $options[] = '<input name="cb:' . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . '__SUM:2" type="checkbox" value="">';
                 $options[] = '<input name="cb:' . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . '__AVG:3" type="checkbox" value="" >';
                 $options[] = '<input name="cb:' . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . '__MIN:4"type="checkbox" value="" >';
                 $options[] = '<input name="cb:' . $columntototalrow['tablename'] . ':' . $columntototalrow['columnname'] . ':' . $columntototalrow['fieldlabel'] . '__MAX:5" type="checkbox" value="" >';
             }
             $options_list[] = $options;
         }
     } while ($columntototalrow = $adb->fetch_array($result));
     $log->info("Reports :: Successfully returned sgetColumnstoTotalHTML");
     return $options_list;
 }
Ejemplo n.º 25
0
function getListViewEntries2($focus, $module, $list_result, $navigation_array, $relatedlist = '', $returnset = '', $edit_action = 'EditView', $del_action = 'Delete', $oCv = '', $page = '', $selectedfields = '', $contRelatedfields = '', $skipActions = false)
{
    global $log;
    global $mod_strings;
    $log->debug("Entering getListViewEntries(" . get_class($focus) . "," . $module . "," . $list_result . "," . $navigation_array . "," . $relatedlist . "," . $returnset . "," . $edit_action . "," . $del_action . "," . (is_object($oCv) ? get_class($oCv) : $oCv) . ") method ...");
    $tabname = getParentTab();
    global $adb, $current_user;
    global $app_strings;
    $noofrows = $adb->num_rows($list_result);
    $list_block = array();
    global $theme;
    $evt_status = '';
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    //getting the vtiger_fieldtable entries from database
    $tabid = getTabid($module);
    //added for vtiger_customview 27/5
    if ($oCv) {
        if (isset($oCv->list_fields)) {
            $focus->list_fields = $oCv->list_fields;
        }
    }
    if (is_array($selectedfields) && $selectedfields != '') {
        $focus->list_fields = $selectedfields;
    }
    // Remove fields which are made inactive
    $focus->filterInactiveFields($module);
    //Added to reduce the no. of queries logging for non-admin user -- by minnie-start
    $field_list = array();
    $j = 0;
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    foreach ($focus->list_fields as $name => $tableinfo) {
        $fieldname = $focus->list_fields_name[$name];
        if ($oCv) {
            if (isset($oCv->list_fields_name)) {
                $fieldname = $oCv->list_fields_name[$name];
            }
        }
        if ($fieldname == 'accountname' && $module != 'Accounts') {
            $fieldname = 'account_id';
        }
        if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
            $fieldname = 'contact_id';
        }
        if ($fieldname == 'productname' && $module != 'Products') {
            $fieldname = 'product_id';
        }
        array_push($field_list, $fieldname);
        $j++;
    }
    $field = array();
    if ($is_admin == false) {
        if ($module == 'Emails') {
            $query = "SELECT fieldname FROM vtiger_field WHERE tabid = ? and vtiger_field.presence in (0,2)";
            $params = array($tabid);
        } else {
            $profileList = getCurrentUserProfileList();
            $params = array();
            $query = "SELECT DISTINCT vtiger_field.fieldname\r\n\t\t\t\tFROM vtiger_field\r\n\t\t\t\tINNER JOIN vtiger_profile2field\r\n\t\t\t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\r\n\t\t\t\tINNER JOIN vtiger_def_org_field\r\n\t\t\t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid";
            if ($module == "Calendar") {
                $query .= " WHERE vtiger_field.tabid in (9,16) and vtiger_field.presence in (0,2)";
            } else {
                $query .= " WHERE vtiger_field.tabid = ? and vtiger_field.presence in (0,2)";
                array_push($params, $tabid);
            }
            $query .= " AND vtiger_profile2field.visible = 0\r\n\t\t\t\t\tAND vtiger_profile2field.visible = 0\r\n\t\t\t\t\tAND vtiger_def_org_field.visible = 0\r\n\t\t\t\t\tAND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")\r\n\t\t\t\t\tAND vtiger_field.fieldname IN (" . generateQuestionMarks($field_list) . ")";
            array_push($params, $profileList, $field_list);
        }
        $result = $adb->pquery($query, $params);
        for ($k = 0; $k < $adb->num_rows($result); $k++) {
            $field[] = $adb->query_result($result, $k, "fieldname");
        }
    }
    //constructing the uitype and columnname array
    $ui_col_array = array();
    $params = array();
    $query = "SELECT uitype, columnname, fieldname FROM vtiger_field ";
    if ($module == "Calendar") {
        $query .= " WHERE vtiger_field.tabid in (9,16) and vtiger_field.presence in (0,2)";
    } else {
        $query .= " WHERE vtiger_field.tabid = ? and vtiger_field.presence in (0,2)";
        array_push($params, $tabid);
    }
    $query .= " AND fieldname IN (" . generateQuestionMarks($field_list) . ") ";
    array_push($params, $field_list);
    $result = $adb->pquery($query, $params);
    $num_rows = $adb->num_rows($result);
    for ($i = 0; $i < $num_rows; $i++) {
        $tempArr = array();
        $uitype = $adb->query_result($result, $i, 'uitype');
        $columnname = $adb->query_result($result, $i, 'columnname');
        $field_name = $adb->query_result($result, $i, 'fieldname');
        $tempArr[$uitype] = $columnname;
        $ui_col_array[$field_name] = $tempArr;
    }
    //end
    if ($navigation_array['start'] != 0) {
        for ($i = 1; $i <= $noofrows; $i++) {
            $list_header = array();
            //Getting the entityid
            if ($module != 'Users') {
                $entity_id = $adb->query_result($list_result, $i - 1, "crmid");
                $owner_id = $adb->query_result($list_result, $i - 1, "smownerid");
            } else {
                $entity_id = $adb->query_result($list_result, $i - 1, "id");
            }
            // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
            // begin: Armando Lüscher 05.07.2005 -> §priority
            // Code contri buted by fredy Desc: Set Priority color
            $priority = $adb->query_result($list_result, $i - 1, "priority");
            $font_color_high = "color:#00DD00;";
            $font_color_medium = "color:#DD00DD;";
            $P_FONT_COLOR = "";
            switch ($priority) {
                case 'High':
                    $P_FONT_COLOR = $font_color_high;
                    break;
                case 'Medium':
                    $P_FONT_COLOR = $font_color_medium;
                    break;
                default:
                    $P_FONT_COLOR = "";
            }
            //end: Armando Lüscher 05.07.2005 -> §priority
            foreach ($focus->list_fields as $name => $tableinfo) {
                $fieldname = $focus->list_fields_name[$name];
                //added for vtiger_customview 27/5
                if ($oCv) {
                    if (isset($oCv->list_fields_name)) {
                        $fieldname = $oCv->list_fields_name[$name];
                        if ($fieldname == 'accountname' && $module != 'Accounts') {
                            $fieldname = 'account_id';
                        }
                        if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
                            $fieldname = 'contact_id';
                        }
                        if ($fieldname == 'productname' && $module != 'Products') {
                            $fieldname = 'product_id';
                        }
                    } else {
                        $fieldname = $focus->list_fields_name[$name];
                    }
                } else {
                    $fieldname = $focus->list_fields_name[$name];
                    if ($fieldname == 'accountname' && $module != 'Accounts') {
                        $fieldname = 'account_id';
                    }
                    if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
                        $fieldname = 'contact_id';
                    }
                    if ($fieldname == 'productname' && $module != 'Products') {
                        $fieldname = 'product_id';
                    }
                }
                if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || in_array($fieldname, $field) || $fieldname == '' || $name == 'Close' && $module == 'Calendar') {
                    if ($fieldname == '') {
                        $table_name = '';
                        $column_name = '';
                        foreach ($tableinfo as $tablename => $colname) {
                            $table_name = $tablename;
                            $column_name = $colname;
                        }
                        $value = $adb->query_result($list_result, $i - 1, $colname);
                    } else {
                        if ($module == 'Calendar') {
                            $act_id = $adb->query_result($list_result, $i - 1, "activityid");
                            $cal_sql = "select activitytype from vtiger_activity where activityid=?";
                            $cal_res = $adb->pquery($cal_sql, array($act_id));
                            if ($adb->num_rows($cal_res) >= 0) {
                                $activitytype = $adb->query_result($cal_res, 0, "activitytype");
                            }
                        }
                        if (($module == 'Calendar' || $module == 'Emails' || $module == 'HelpDesk' || $module == 'Invoice' || $module == 'Leads' || $module == 'Contacts') && ($fieldname == 'parent_id' || $name == 'Contact Name' || $name == 'Close' || $fieldname == 'firstname')) {
                            if ($module == 'Calendar') {
                                if ($fieldname == 'status') {
                                    if ($activitytype == 'Task') {
                                        $fieldname = 'taskstatus';
                                    } else {
                                        $fieldname = 'eventstatus';
                                    }
                                }
                                if ($activitytype == 'Task') {
                                    if (getFieldVisibilityPermission('Calendar', $current_user->id, $fieldname) == '0') {
                                        $has_permission = 'yes';
                                    } else {
                                        $has_permission = 'no';
                                    }
                                } else {
                                    if (getFieldVisibilityPermission('Events', $current_user->id, $fieldname) == '0') {
                                        $has_permission = 'yes';
                                    } else {
                                        $has_permission = 'no';
                                    }
                                }
                            }
                            if ($module != 'Calendar' || $module == 'Calendar' && $has_permission == 'yes') {
                                if ($fieldname == 'parent_id') {
                                    $value = getRelatedTo($module, $list_result, $i - 1);
                                }
                                if ($name == 'Contact Name') {
                                    $contact_id = $adb->query_result($list_result, $i - 1, "contactid");
                                    $contact_name = getFullNameFromQResult($list_result, $i - 1, "Contacts");
                                    $value = "";
                                    //Added to get the contactname for activities custom view - t=2190
                                    if ($contact_id != '' && !empty($contact_name)) {
                                        $contact_name = getContactName($contact_id);
                                    }
                                    if ($contact_name != "" && $contact_id != 'NULL') {
                                        // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
                                        $value = "<a href='index.php?module=Contacts&action=DetailView&parenttab=" . $tabname . "&record=" . $contact_id . "' style='" . $P_FONT_COLOR . "'>" . $contact_name . "</a>";
                                        // Armando Lüscher 05.07.2005 -> §priority -> Desc: inserted style="$P_FONT_COLOR"
                                    }
                                }
                                if ($fieldname == "firstname") {
                                    $first_name = textlength_check($adb->query_result($list_result, $i - 1, "firstname"));
                                    $value = '<a href="index.php?action=DetailView&module=' . $module . '&parenttab=' . $tabname . '&record=' . $entity_id . '">' . $first_name . '</a>';
                                }
                                if ($name == 'Close') {
                                    $status = $adb->query_result($list_result, $i - 1, "status");
                                    $activityid = $adb->query_result($list_result, $i - 1, "activityid");
                                    if (empty($activityid)) {
                                        $activityid = $adb->query_result($list_result, $i - 1, "tmp_activity_id");
                                    }
                                    $activitytype = $adb->query_result($list_result, $i - 1, "activitytype");
                                    // TODO - Picking activitytype when it is not present in the Custom View.
                                    // Going forward, this column should be added to the select list if not already present as a performance improvement.
                                    if (empty($activitytype)) {
                                        $activitytypeRes = $adb->pquery('SELECT activitytype FROM vtiger_activity WHERE activityid=?', array($activityid));
                                        if ($adb->num_rows($activitytypeRes) > 0) {
                                            $activitytype = $adb->query_result($activitytypeRes, 0, 'activitytype');
                                        }
                                    }
                                    if ($activitytype != 'Task' && $activitytype != 'Emails') {
                                        $eventstatus = $adb->query_result($list_result, $i - 1, "eventstatus");
                                        if (isset($eventstatus)) {
                                            $status = $eventstatus;
                                        }
                                    }
                                    if ($status == 'Deferred' || $status == 'Completed' || $status == 'Held' || $status == '') {
                                        $value = "";
                                    } else {
                                        if ($activitytype == 'Task') {
                                            $evt_status = '&status=Completed';
                                        } else {
                                            $evt_status = '&eventstatus=Held';
                                        }
                                        if (isPermitted("Calendar", 'EditView', $activityid) == 'yes') {
                                            if ($returnset == '') {
                                                $returnset = '&return_module=Calendar&return_action=ListView&return_id=' . $activityid . '&return_viewname=' . $oCv->setdefaultviewid;
                                            }
                                            // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
                                            $value = "<a href='index.php?action=Save&module=Calendar&record=" . $activityid . "&parenttab=" . $tabname . "&change_status=true" . $returnset . $evt_status . "&start=" . $navigation_array['current'] . "' style='" . $P_FONT_COLOR . "'>X</a>";
                                            // Armando Lüscher 05.07.2005 -> §priority -> Desc: inserted style="$P_FONT_COLOR"
                                        } else {
                                            $value = "";
                                        }
                                    }
                                }
                            } else {
                                $value = "";
                            }
                        } elseif ($module == "Documents" && ($fieldname == 'filelocationtype' || $fieldname == 'filename' || $fieldname == 'filesize' || $fieldname == 'filestatus' || $fieldname == 'filetype')) {
                            $value = $adb->query_result($list_result, $i - 1, $fieldname);
                            if ($fieldname == 'filelocationtype') {
                                if ($value == 'I') {
                                    $value = getTranslatedString('LBL_INTERNAL', $module);
                                } elseif ($value == 'E') {
                                    $value = getTranslatedString('LBL_EXTERNAL', $module);
                                } else {
                                    $value = ' --';
                                }
                            }
                            if ($fieldname == 'filename') {
                                $downloadtype = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                if ($downloadtype == 'I') {
                                    $fld_value = $value;
                                    $ext_pos = strrpos($fld_value, ".");
                                    $ext = substr($fld_value, $ext_pos + 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) != '') {
                                        $fld_value = $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 {
                                        $fld_value = '--';
                                        $fileicon = '';
                                    }
                                } else {
                                    $fld_value = ' --';
                                    $fileicon = '';
                                }
                                $file_name = $adb->query_result($list_result, $i - 1, 'filename');
                                $notes_id = $adb->query_result($list_result, $i - 1, 'crmid');
                                $folder_id = $adb->query_result($list_result, $i - 1, 'folderid');
                                $download_type = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                $file_status = $adb->query_result($list_result, $i - 1, 'filestatus');
                                $fileidQuery = "select attachmentsid from vtiger_seattachmentsrel where crmid=?";
                                $fileidres = $adb->pquery($fileidQuery, array($notes_id));
                                $fileid = $adb->query_result($fileidres, 0, 'attachmentsid');
                                if ($file_name != '' && $file_status == 1) {
                                    if ($download_type == 'I') {
                                        $fld_value = "<a href='index.php?module=uploads&action=downloadfile&entityid={$notes_id}&fileid={$fileid}' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "' onclick='javascript:dldCntIncrease({$notes_id});'>" . $fld_value . "</a>";
                                    } elseif ($download_type == 'E') {
                                        $fld_value = "<a target='_blank' href='{$file_name}' onclick='javascript:dldCntIncrease({$notes_id});' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "'>" . $fld_value . "</a>";
                                    } else {
                                        $fld_value = ' --';
                                    }
                                }
                                $value = $fileicon . $fld_value;
                            }
                            if ($fieldname == 'filesize') {
                                $downloadtype = $adb->query_result($list_result, $i - 1, '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 = ' --';
                                }
                            }
                            if ($fieldname == 'filestatus') {
                                $filestatus = $value;
                                if ($filestatus == 1) {
                                    $value = getTranslatedString('yes', $module);
                                } elseif ($filestatus == 0) {
                                    $value = getTranslatedString('no', $module);
                                } else {
                                    $value = ' --';
                                }
                            }
                            if ($fieldname == 'filetype') {
                                $downloadtype = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                $filetype = $adb->query_result($list_result, $i - 1, 'filetype');
                                if ($downloadtype == 'E' || $downloadtype != 'I') {
                                    $value = ' --';
                                } else {
                                    $value = $filetype;
                                }
                            }
                            if ($fieldname == 'notecontent') {
                                $value = decode_html($value);
                                $value = textlength_check($value);
                            }
                        } elseif ($module == "Products" && $name == "Related to") {
                            $value = getRelatedTo($module, $list_result, $i - 1);
                        } elseif ($name == 'Contact Name' && ($module == 'SalesOrder' || $module == 'Quotes' || $module == 'PurchaseOrder')) {
                            if ($name == 'Contact Name') {
                                $contact_id = $adb->query_result($list_result, $i - 1, "contactid");
                                $contact_name = getFullNameFromQResult($list_result, $i - 1, "Contacts");
                                $value = "";
                                if ($contact_name != "" && $contact_id != 'NULL') {
                                    $value = "<a href='index.php?module=Contacts&action=DetailView&parenttab=" . $tabname . "&record=" . $contact_id . "' style='" . $P_FONT_COLOR . "'>" . $contact_name . "</a>";
                                }
                            }
                        } elseif ($name == 'Product') {
                            $product_id = textlength_check($adb->query_result($list_result, $i - 1, "productname"));
                            $value = $product_id;
                        } elseif ($name == 'Account Name') {
                            //modified for vtiger_customview 27/5
                            if ($module == 'Accounts') {
                                $account_id = $adb->query_result($list_result, $i - 1, "crmid");
                                //$account_name = getAccountName($account_id);
                                $account_name = textlength_check($adb->query_result($list_result, $i - 1, "accountname"));
                                // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
                                $value = '<a href="index.php?module=Accounts&action=DetailView&record=' . $account_id . '&parenttab=' . $tabname . '" style="' . $P_FONT_COLOR . '">' . $account_name . '</a>';
                                // Armando Lüscher 05.07.2005 -> §priority -> Desc: inserted style="$P_FONT_COLOR"
                            } elseif ($module == 'Potentials' || $module == 'Contacts' || $module == 'Invoice' || $module == 'SalesOrder' || $module == 'Quotes') {
                                //Potential,Contacts,Invoice,SalesOrder & Quotes  records   sort by Account Name
                                $accountname = textlength_check($adb->query_result($list_result, $i - 1, "accountname"));
                                $accountid = $adb->query_result($list_result, $i - 1, "accountid");
                                $value = '<a href="index.php?module=Accounts&action=DetailView&record=' . $accountid . '&parenttab=' . $tabname . '" style="' . $P_FONT_COLOR . '">' . $accountname . '</a>';
                            } else {
                                $account_id = $adb->query_result($list_result, $i - 1, "accountid");
                                $account_name = getAccountName($account_id);
                                $acc_name = textlength_check($account_name);
                                // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
                                $value = '<a href="index.php?module=Accounts&action=DetailView&record=' . $account_id . '&parenttab=' . $tabname . '" style="' . $P_FONT_COLOR . '">' . $acc_name . '</a>';
                                // Armando Lüscher 05.07.2005 -> §priority -> Desc: inserted style="$P_FONT_COLOR"
                            }
                        } elseif (($module == 'HelpDesk' || $module == 'PriceBook' || $module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'Faq') && $name == 'Product Name') {
                            if ($module == 'HelpDesk' || $module == 'Faq') {
                                $product_id = $adb->query_result($list_result, $i - 1, "product_id");
                            } else {
                                $product_id = $adb->query_result($list_result, $i - 1, "productid");
                            }
                            if ($product_id != '') {
                                $product_name = getProductName($product_id);
                            } else {
                                $product_name = '';
                            }
                            $value = '<a href="index.php?module=Products&action=DetailView&parenttab=' . $tabname . '&record=' . $product_id . '">' . textlength_check($product_name) . '</a>';
                        } elseif ($module == 'Quotes' && $name == 'Potential Name' || $module == 'SalesOrder' && $name == 'Potential Name') {
                            $potential_id = $adb->query_result($list_result, $i - 1, "potentialid");
                            $potential_name = getPotentialName($potential_id);
                            $value = '<a href="index.php?module=Potentials&action=DetailView&parenttab=' . $tabname . '&record=' . $potential_id . '">' . textlength_check($potential_name) . '</a>';
                        } elseif ($module == 'Emails' && $relatedlist != '' && ($name == 'Subject' || $name == 'Date Sent' || $name == 'To')) {
                            $list_result_count = $i - 1;
                            $tmp_value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
                            $value = '<a href="javascript:;" onClick="ShowEmail(\'' . $entity_id . '\');">' . textlength_check($tmp_value) . '</a>';
                            if ($name == 'Date Sent') {
                                $sql = "select email_flag from vtiger_emaildetails where emailid=?";
                                $result = $adb->pquery($sql, array($entity_id));
                                $email_flag = $adb->query_result($result, 0, "email_flag");
                                if ($email_flag != 'SAVED') {
                                    $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
                                } else {
                                    $value = '';
                                }
                            }
                        } elseif ($module == 'Calendar' && ($fieldname != 'taskstatus' && $fieldname != 'eventstatus')) {
                            if ($activitytype == 'Task') {
                                if (getFieldVisibilityPermission('Calendar', $current_user->id, $fieldname) == '0') {
                                    $list_result_count = $i - 1;
                                    $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
                                } else {
                                    $value = '';
                                }
                            } else {
                                if (getFieldVisibilityPermission('Events', $current_user->id, $fieldname) == '0') {
                                    $list_result_count = $i - 1;
                                    $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
                                } else {
                                    $value = '';
                                }
                            }
                        } elseif ($module == "Accounting" && $fieldname == "accounting_id") {
                            $list_result_count = $i - 1;
                            $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
                            $value = '<a href="index.php?action=DetailView&module=' . $module . '&parenttab=' . $tabname . '&record=' . $entity_id . '">' . $value . '</a>';
                        } else {
                            $list_result_count = $i - 1;
                            $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
                        }
                    }
                    // vtlib customization: For listview javascript triggers
                    $value = "{$value} <span type='vtlib_metainfo' vtrecordid='{$entity_id}' vtfieldname='{$fieldname}' vtmodule='{$module}' style='display:none;'></span>";
                    // END
                    if ($module == "Calendar" && $name == $app_strings['Close']) {
                        if (isPermitted("Calendar", "EditView") == 'yes') {
                            if (getFieldVisibilityPermission('Events', $current_user->id, 'eventstatus') == '0' || getFieldVisibilityPermission('Calendar', $current_user->id, 'taskstatus') == '0') {
                                array_push($list_header, $value);
                            }
                        }
                    } else {
                        $list_header[] = $value;
                    }
                }
            }
            $varreturnset = '';
            if ($returnset == '') {
                $varreturnset = '&return_module=' . $module . '&return_action=index';
            } else {
                $varreturnset = $returnset;
            }
            if ($module == 'Calendar') {
                $actvity_type = $adb->query_result($list_result, $list_result_count, 'activitytype');
                if ($actvity_type == 'Task') {
                    $varreturnset .= '&activity_mode=Task';
                } else {
                    $varreturnset .= '&activity_mode=Events';
                }
            }
            //Added for Actions ie., edit and delete links in listview
            $links_info = "";
            if (!(is_array($selectedfields) && $selectedfields != '')) {
                if (isPermitted($module, "EditView", "") == 'yes') {
                    $edit_link = getListViewEditLink($module, $entity_id, $relatedlist, $varreturnset, $list_result, $list_result_count);
                    if (isset($_REQUEST['start']) && $_REQUEST['start'] > 1 && $module != 'Emails') {
                        $links_info .= "<a href=\"{$edit_link}&start=" . vtlib_purify($_REQUEST['start']) . "\">" . $app_strings["LNK_EDIT"] . "</a> ";
                    } else {
                        $links_info .= "<a href=\"{$edit_link}\">" . $app_strings["LNK_EDIT"] . "</a> ";
                    }
                }
                if (isPermitted($module, "Delete", "") == 'yes') {
                    $del_link = getListViewDeleteLink($module, $entity_id, $relatedlist, $varreturnset);
                    if ($links_info != "" && $del_link != "") {
                        $links_info .= " | ";
                    }
                    if ($del_link != "") {
                        $links_info .= "<a href='javascript:confirmdelete(\"" . addslashes(urlencode($del_link)) . "\")'>" . $app_strings["LNK_DELETE"] . "</a>";
                    }
                }
            }
            // Record Change Notification
            if (method_exists($focus, 'isViewed') && PerformancePrefs::getBoolean('LISTVIEW_RECORD_CHANGE_INDICATOR', true)) {
                if (!$focus->isViewed($entity_id)) {
                    $links_info .= " | <img src='" . vtiger_imageurl('important1.gif', $theme) . "' border=0>";
                }
            }
            // END
            if ($links_info != "" && !$skipActions) {
                $list_header[] = $links_info;
            }
            //	$list_block[$entity_id] = $list_header;
            if (isset($_SESSION['partialpaymentview']) && $_SESSION['partialpaymentview'] == "true") {
                $list_block[$entity_id . "_" . $i] = $list_header;
            } else {
                $list_block[$entity_id] = $list_header;
            }
        }
    }
    $log->debug("Exiting getListViewEntries method ...");
    return $list_block;
}
Ejemplo n.º 26
0
 /** to get the standard filter fields or the given module 
  * @param $module :: Type String
  * @returns  $stdcriteria_list Array in the following format
  * $stdcriteria_list = Array( $tablename:$columnname:$fieldname:$module_$fieldlabel => $fieldlabel,
  *			 $tablename1:$columnname1:$fieldname1:$module_$fieldlabel1 => $fieldlabel1,  
  *					|
  *			 $tablenamen:$columnnamen:$fieldnamen:$module_$fieldlabeln => $fieldlabeln)  
  */
 function getStdCriteriaByModule($module)
 {
     global $adb;
     $tabid = getTabid($module);
     global $current_user;
     require 'user_privileges/user_privileges_' . $current_user->id . '.php';
     $module_info = $this->getCustomViewModuleInfo($module);
     foreach ($this->module_list[$module] as $key => $blockid) {
         $blockids[] = $blockid;
     }
     if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
         $sql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid ";
         $sql .= " where vtiger_field.tabid=? and vtiger_field.block in (" . generateQuestionMarks($blockids) . ")\n                        and vtiger_field.uitype in (5,6,23,70)";
         $sql .= " and vtiger_field.presence in (0,2) order by vtiger_field.sequence";
         $params = array($tabid, $blockids);
     } else {
         $profileList = getCurrentUserProfileList();
         $sql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid inner join  vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid ";
         $sql .= " where vtiger_field.tabid=? and vtiger_field.block in (" . generateQuestionMarks($blockids) . ") and vtiger_field.uitype in (5,6,23,70)";
         $sql .= " and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
         $params = array($tabid, $blockids);
         if (count($profileList) > 0) {
             $sql .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")";
             array_push($params, $profileList);
         }
         $sql .= " order by vtiger_field.sequence";
     }
     $result = $adb->pquery($sql, $params);
     while ($criteriatyperow = $adb->fetch_array($result)) {
         $fieldtablename = $criteriatyperow["tablename"];
         $fieldcolname = $criteriatyperow["columnname"];
         $fieldlabel = $criteriatyperow["fieldlabel"];
         $fieldname = $criteriatyperow["fieldname"];
         $fieldlabel1 = str_replace(" ", "_", $fieldlabel);
         $optionvalue = $fieldtablename . ":" . $fieldcolname . ":" . $fieldname . ":" . $module . "_" . $fieldlabel1;
         $stdcriteria_list[$optionvalue] = $fieldlabel;
     }
     return $stdcriteria_list;
 }
Ejemplo n.º 27
0
function getSearchingListViewEntries($focus, $module, $list_result, $navigation_array, $relatedlist = '', $returnset = '', $edit_action = 'EditView', $del_action = 'Delete', $oCv = '', $page = '', $selectedfields = '', $contRelatedfields = '', $skipActions = false, $linksallowed = false)
{
    global $log;
    global $mod_strings;
    $log->debug("Entering getSearchingListViewEntries(" . get_class($focus) . "," . $module . "," . $list_result . "," . $navigation_array . "," . $relatedlist . "," . $returnset . "," . $edit_action . "," . $del_action . "," . (is_object($oCv) ? get_class($oCv) : $oCv) . ") method ...");
    $tabname = getParentTab();
    global $adb, $current_user;
    global $app_strings;
    $noofrows = $adb->num_rows($list_result);
    $list_block = array();
    global $theme;
    $evt_status = '';
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    //getting the vtiger_fieldtable entries from database
    $tabid = getTabid($module);
    //added for vtiger_customview 27/5
    if ($oCv) {
        if (isset($oCv->list_fields)) {
            $focus->list_fields = $oCv->list_fields;
        }
    }
    if (is_array($selectedfields) && $selectedfields != '') {
        $focus->list_fields = $selectedfields;
    }
    // Remove fields which are made inactive
    $focus->filterInactiveFields($module);
    //Added to reduce the no. of queries logging for non-admin user -- by minnie-start
    $field_list = array();
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    foreach ($focus->list_fields as $name => $tableinfo) {
        $fieldname = $focus->list_fields_name[$name];
        if ($oCv) {
            if (isset($oCv->list_fields_name)) {
                $fieldname = $oCv->list_fields_name[$name];
            }
        }
        if ($fieldname == 'accountname' && $module != 'Accounts') {
            $fieldname = 'account_id';
        }
        if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
            $fieldname = 'contact_id';
        }
        if ($fieldname == 'productname' && $module != 'Products') {
            $fieldname = 'product_id';
        }
        array_push($field_list, $fieldname);
    }
    $field = array();
    if ($is_admin == false) {
        if ($module == 'Emails') {
            $query = "SELECT fieldname FROM vtiger_field WHERE tabid = ? and vtiger_field.presence in (0,2)";
            $params = array($tabid);
        } else {
            $profileList = getCurrentUserProfileList();
            $params = array();
            $query = "SELECT DISTINCT vtiger_field.fieldname\n\t\t\tFROM vtiger_field\n\t\t\tINNER JOIN vtiger_profile2field\n\t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\tINNER JOIN vtiger_def_org_field\n\t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid";
            if ($module == "Calendar") {
                $query .= " WHERE vtiger_field.tabid in (9,16) and vtiger_field.presence in (0,2)";
            } else {
                $query .= " WHERE vtiger_field.tabid = ? and vtiger_field.presence in (0,2)";
                array_push($params, $tabid);
            }
            $query .= " AND vtiger_profile2field.visible = 0\n\t\t\tAND vtiger_profile2field.visible = 0\n\t\t\tAND vtiger_def_org_field.visible = 0\n\t\t\tAND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")\n\t\t\tAND vtiger_field.fieldname IN (" . generateQuestionMarks($field_list) . ")";
            array_push($params, $profileList, $field_list);
        }
        $result = $adb->pquery($query, $params);
        for ($k = 0; $k < $adb->num_rows($result); $k++) {
            $field[] = $adb->query_result($result, $k, "fieldname");
        }
    }
    //constructing the uitype and columnname array
    $ui_col_array = array();
    $params = array();
    $query = "SELECT uitype, columnname, fieldname FROM vtiger_field ";
    if ($module == "Calendar") {
        $query .= " WHERE vtiger_field.tabid in (9,16) and vtiger_field.presence in (0,2)";
    } else {
        $query .= " WHERE vtiger_field.tabid = ? and vtiger_field.presence in (0,2)";
        array_push($params, $tabid);
    }
    $query .= " AND fieldname IN (" . generateQuestionMarks($field_list) . ") ";
    array_push($params, $field_list);
    $result = $adb->pquery($query, $params);
    $num_rows = $adb->num_rows($result);
    for ($i = 0; $i < $num_rows; $i++) {
        $tempArr = array();
        $uitype = $adb->query_result($result, $i, 'uitype');
        $columnname = $adb->query_result($result, $i, 'columnname');
        $field_name = $adb->query_result($result, $i, 'fieldname');
        $tempArr[$uitype] = $columnname;
        $ui_col_array[$field_name] = $tempArr;
    }
    //end
    if ($navigation_array['start'] != 0) {
        for ($i = 1; $i <= $noofrows; $i++) {
            $list_header = array();
            //Getting the entityid
            if ($module != 'Users') {
                $entity_id = $adb->query_result($list_result, $i - 1, "crmid");
                $owner_id = $adb->query_result($list_result, $i - 1, "smownerid");
            } else {
                $entity_id = $adb->query_result($list_result, $i - 1, "id");
            }
            foreach ($focus->list_fields as $name => $tableinfo) {
                $fieldname = $focus->list_fields_name[$name];
                //added for vtiger_customview 27/5
                if ($oCv) {
                    if (isset($oCv->list_fields_name)) {
                        $fieldname = $oCv->list_fields_name[$name];
                        if ($fieldname == 'accountname' && $module != 'Accounts') {
                            $fieldname = 'account_id';
                        }
                        if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
                            $fieldname = 'contact_id';
                        }
                        if ($fieldname == 'productname' && $module != 'Products') {
                            $fieldname = 'product_id';
                        }
                    } else {
                        $fieldname = $focus->list_fields_name[$name];
                    }
                } else {
                    $fieldname = $focus->list_fields_name[$name];
                    if ($fieldname == 'accountname' && $module != 'Accounts') {
                        $fieldname = 'account_id';
                    }
                    if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
                        $fieldname = 'contact_id';
                    }
                    if ($fieldname == 'productname' && $module != 'Products') {
                        $fieldname = 'product_id';
                    }
                }
                if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || in_array($fieldname, $field) || $fieldname == '' || $name == 'Close' && $module == 'Calendar') {
                    if ($fieldname == '') {
                        $table_name = '';
                        $column_name = '';
                        foreach ($tableinfo as $tablename => $colname) {
                            $table_name = $tablename;
                            $column_name = $colname;
                        }
                        $value = $adb->query_result($list_result, $i - 1, $colname);
                    } else {
                        if ($module == 'Calendar') {
                            $act_id = $adb->query_result($list_result, $i - 1, "activityid");
                            $cal_sql = "select activitytype from vtiger_activity where activityid=?";
                            $cal_res = $adb->pquery($cal_sql, array($act_id));
                            if ($adb->num_rows($cal_res) >= 0) {
                                $activitytype = $adb->query_result($cal_res, 0, "activitytype");
                            }
                        }
                        if (($module == 'Calendar' || $module == 'Emails' || $module == 'HelpDesk' || $module == 'Invoice' || $module == 'Leads' || $module == 'Contacts') && ($fieldname == 'parent_id' || $name == 'Contact Name' || $name == 'Close' || $fieldname == 'firstname')) {
                            if ($module == 'Calendar') {
                                if ($fieldname == 'status') {
                                    if ($activitytype == 'Task') {
                                        $fieldname = 'taskstatus';
                                    } else {
                                        $fieldname = 'eventstatus';
                                    }
                                }
                                if ($activitytype == 'Task') {
                                    if (getFieldVisibilityPermission('Calendar', $current_user->id, $fieldname) == '0') {
                                        $has_permission = 'yes';
                                    } else {
                                        $has_permission = 'no';
                                    }
                                } else {
                                    if (getFieldVisibilityPermission('Events', $current_user->id, $fieldname) == '0') {
                                        $has_permission = 'yes';
                                    } else {
                                        $has_permission = 'no';
                                    }
                                }
                            }
                            if ($module != 'Calendar' || $module == 'Calendar' && $has_permission == 'yes') {
                                if ($fieldname == 'parent_id') {
                                    $value = getRelatedTo($module, $list_result, $i - 1);
                                }
                                if ($name == 'Contact Name') {
                                    $contact_id = $adb->query_result($list_result, $i - 1, "contactid");
                                    $contact_name = getFullNameFromQResult($list_result, $i - 1, "Contacts");
                                    $value = "";
                                    //Added to get the contactname for activities custom view - t=2190
                                    if ($contact_id != '' && !empty($contact_name)) {
                                        $contact_name = getContactName($contact_id);
                                    }
                                    if ($contact_name != "" && $contact_id != 'NULL') {
                                        $value = $contact_name;
                                    }
                                }
                                if ($fieldname == "firstname") {
                                    $first_name = textlength_check($adb->query_result($list_result, $i - 1, "firstname"));
                                    $value = $first_name;
                                }
                                if ($name == 'Close') {
                                    $status = $adb->query_result($list_result, $i - 1, "status");
                                    $activityid = $adb->query_result($list_result, $i - 1, "activityid");
                                    if (empty($activityid)) {
                                        $activityid = $adb->query_result($list_result, $i - 1, "tmp_activity_id");
                                    }
                                    $activitytype = $adb->query_result($list_result, $i - 1, "activitytype");
                                    // TODO - Picking activitytype when it is not present in the Custom View.
                                    // Going forward, this column should be added to the select list if not already present as a performance improvement.
                                    if (empty($activitytype)) {
                                        $activitytypeRes = $adb->pquery('SELECT activitytype FROM vtiger_activity WHERE activityid=?', array($activityid));
                                        if ($adb->num_rows($activitytypeRes) > 0) {
                                            $activitytype = $adb->query_result($activitytypeRes, 0, 'activitytype');
                                        }
                                    }
                                    if ($activitytype != 'Task' && $activitytype != 'Emails') {
                                        $eventstatus = $adb->query_result($list_result, $i - 1, "eventstatus");
                                        if (isset($eventstatus)) {
                                            $status = $eventstatus;
                                        }
                                    }
                                    if ($status == 'Deferred' || $status == 'Completed' || $status == 'Held' || $status == '') {
                                        $value = "";
                                    } else {
                                        if ($activitytype == 'Task') {
                                            $evt_status = '&status=Completed';
                                        } else {
                                            $evt_status = '&eventstatus=Held';
                                        }
                                    }
                                }
                            } else {
                                $value = "";
                            }
                        } elseif ($module == "Documents" && ($fieldname == 'filelocationtype' || $fieldname == 'filename' || $fieldname == 'filesize' || $fieldname == 'filestatus' || $fieldname == 'filetype')) {
                            $value = $adb->query_result($list_result, $i - 1, $fieldname);
                            if ($fieldname == 'filelocationtype') {
                                if ($value == 'I') {
                                    $value = getTranslatedString('LBL_INTERNAL', $module);
                                } elseif ($value == 'E') {
                                    $value = getTranslatedString('LBL_EXTERNAL', $module);
                                } else {
                                    $value = ' --';
                                }
                            }
                            if ($fieldname == 'filename') {
                                $downloadtype = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                if ($downloadtype == 'I') {
                                    $fld_value = $value;
                                    $ext_pos = strrpos($fld_value, ".");
                                    $ext = substr($fld_value, $ext_pos + 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) != '') {
                                        $fld_value = $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 {
                                        $fld_value = '--';
                                        $fileicon = '';
                                    }
                                } else {
                                    $fld_value = ' --';
                                    $fileicon = '';
                                }
                                $file_name = $adb->query_result($list_result, $i - 1, 'filename');
                                $notes_id = $adb->query_result($list_result, $i - 1, 'crmid');
                                $folder_id = $adb->query_result($list_result, $i - 1, 'folderid');
                                $download_type = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                $file_status = $adb->query_result($list_result, $i - 1, 'filestatus');
                                $fileidQuery = "select attachmentsid from vtiger_seattachmentsrel where crmid=?";
                                $fileidres = $adb->pquery($fileidQuery, array($notes_id));
                                $fileid = $adb->query_result($fileidres, 0, 'attachmentsid');
                                if ($file_name != '' && $file_status == 1) {
                                    if ($download_type == 'I') {
                                        $fld_value = "<a href='index.php?module=uploads&action=downloadfile&entityid={$notes_id}&fileid={$fileid}' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "' onclick='javascript:dldCntIncrease({$notes_id});'>" . $fld_value . "</a>";
                                    } elseif ($download_type == 'E') {
                                        $fld_value = "<a target='_blank' href='{$file_name}' onclick='javascript:dldCntIncrease({$notes_id});' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "'>" . $fld_value . "</a>";
                                    } else {
                                        $fld_value = ' --';
                                    }
                                }
                                $value = $fileicon . $fld_value;
                            }
                            if ($fieldname == 'filesize') {
                                $downloadtype = $adb->query_result($list_result, $i - 1, '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 = ' --';
                                }
                            }
                            if ($fieldname == 'filestatus') {
                                $filestatus = $value;
                                if ($filestatus == 1) {
                                    $value = getTranslatedString('yes', $module);
                                } elseif ($filestatus == 0) {
                                    $value = getTranslatedString('no', $module);
                                } else {
                                    $value = ' --';
                                }
                            }
                            if ($fieldname == 'filetype') {
                                $downloadtype = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                $filetype = $adb->query_result($list_result, $i - 1, 'filetype');
                                if ($downloadtype == 'E' || $downloadtype != 'I') {
                                    $value = ' --';
                                } else {
                                    $value = $filetype;
                                }
                            }
                            if ($fieldname == 'notecontent') {
                                $value = decode_html($value);
                                $value = textlength_check($value);
                            }
                        } elseif ($module == "Products" && $name == "Related to") {
                            $value = getRelatedTo($module, $list_result, $i - 1);
                        } elseif ($name == 'Contact Name' && ($module == 'SalesOrder' || $module == 'Quotes' || $module == 'PurchaseOrder')) {
                            if ($name == 'Contact Name') {
                                $contact_id = $adb->query_result($list_result, $i - 1, "contactid");
                                $contact_name = getFullNameFromQResult($list_result, $i - 1, "Contacts");
                                $value = "";
                                if ($contact_name != "" && $contact_id != 'NULL') {
                                    $value = $contact_name;
                                }
                            }
                        } elseif ($name == 'Product') {
                            $product_id = textlength_check($adb->query_result($list_result, $i - 1, "productname"));
                            $value = $product_id;
                        } elseif ($name == 'Account Name') {
                            //modified for vtiger_customview 27/5
                            if ($module == 'Accounts') {
                                $account_id = $adb->query_result($list_result, $i - 1, "crmid");
                                //$account_name = getAccountName($account_id);
                                $account_name = textlength_check($adb->query_result($list_result, $i - 1, "accountname"));
                                $value = $account_name;
                            } elseif ($module == 'Potentials' || $module == 'Contacts' || $module == 'Invoice' || $module == 'SalesOrder' || $module == 'Quotes') {
                                //Potential,Contacts,Invoice,SalesOrder & Quotes  records   sort by Account Name
                                //$accountname = textlength_check($adb->query_result($list_result,$i-1,"accountname"));
                                $accountid = $adb->query_result($list_result, $i - 1, "accountid");
                                $accountname = textlength_check(getAccountName($accountid));
                                $value = $accountname;
                            } else {
                                $account_id = $adb->query_result($list_result, $i - 1, "accountid");
                                $account_name = getAccountName($account_id);
                                $acc_name = textlength_check($account_name);
                                $value = $acc_name;
                            }
                        } elseif (($module == 'HelpDesk' || $module == 'PriceBook' || $module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'Faq') && $name == 'Product Name') {
                            if ($module == 'HelpDesk' || $module == 'Faq') {
                                $product_id = $adb->query_result($list_result, $i - 1, "product_id");
                            } else {
                                $product_id = $adb->query_result($list_result, $i - 1, "productid");
                            }
                            if ($product_id != '') {
                                $product_name = getProductName($product_id);
                            } else {
                                $product_name = '';
                            }
                            $value = textlength_check($product_name);
                        } elseif ($module == 'Quotes' && $name == 'Potential Name' || $module == 'SalesOrder' && $name == 'Potential Name') {
                            $potential_id = $adb->query_result($list_result, $i - 1, "potentialid");
                            $potential_name = getPotentialName($potential_id);
                            $value = textlength_check($potential_name);
                        } elseif ($module == 'Emails' && $relatedlist != '' && ($name == 'Subject' || $name == 'Date Sent' || $name == 'To')) {
                            $list_result_count = $i - 1;
                            $tmp_value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid, false);
                            $tmp_value = evvt_strip_html_links($tmp_value);
                            $value = textlength_check($tmp_value);
                            if ($name == 'Date Sent') {
                                $sql = "select email_flag from vtiger_emaildetails where emailid=?";
                                $result = $adb->pquery($sql, array($entity_id));
                                $email_flag = $adb->query_result($result, 0, "email_flag");
                                if ($email_flag != 'SAVED') {
                                    $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid, false);
                                    $value = evvt_strip_html_links($value);
                                } else {
                                    $value = '';
                                }
                            }
                        } elseif ($module == 'Calendar' && ($fieldname != 'taskstatus' && $fieldname != 'eventstatus')) {
                            if ($activitytype == 'Task') {
                                if (getFieldVisibilityPermission('Calendar', $current_user->id, $fieldname) == '0') {
                                    $list_result_count = $i - 1;
                                    $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid, false);
                                    $value = evvt_strip_html_links($value);
                                } else {
                                    $value = '';
                                }
                            } else {
                                if (getFieldVisibilityPermission('Events', $current_user->id, $fieldname) == '0') {
                                    $list_result_count = $i - 1;
                                    $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid, false);
                                    $value = evvt_strip_html_links($value);
                                } else {
                                    $value = '';
                                }
                            }
                        } else {
                            $list_result_count = $i - 1;
                            $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid, false);
                            $value = evvt_strip_html_links($value);
                        }
                    }
                    // vtlib customization: For listview javascript triggers
                    //$value = "$value <span type='vtlib_metainfo' vtrecordid='{$entity_id}' vtfieldname='{$fieldname}' vtmodule='$module' style='display:none;'></span>";
                    // END
                    if ($module == "Calendar" && $name == $app_strings['Close']) {
                        if (isPermitted("Calendar", "EditView") == 'yes') {
                            if (getFieldVisibilityPermission('Events', $current_user->id, 'eventstatus') == '0' || getFieldVisibilityPermission('Calendar', $current_user->id, 'taskstatus') == '0') {
                                array_push($list_header, $value);
                            }
                        }
                    } else {
                        $list_header[] = $value;
                    }
                }
            }
            $varreturnset = '';
            $varreturnset = $returnset;
            $webserviceEntityId = vtyiicpng_getWSEntityId($module);
            $list_header[] = $webserviceEntityId . $entity_id;
            $list_header[] = $module;
            $list_block[$entity_id] = $list_header;
        }
    }
    $log->debug("Exiting getSearchingListViewEntries method ...");
    return $list_block;
}
Ejemplo n.º 28
0
function AddLead($user_name, $first_name, $last_name, $email_address, $account_name, $salutation, $title, $phone_mobile, $reports_to, $primary_address_street, $website, $primary_address_city, $primary_address_state, $primary_address_postalcode, $primary_address_country, $alt_address_city, $alt_address_street, $alt_address_state, $alt_address_postalcode, $alt_address_country, $office_phone = "", $home_phone = "", $fax = "", $department = "", $password, $description = "")
{
    if (authentication($user_name, $password)) {
        global $adb;
        global $current_user;
        require_once 'modules/Users/Users.php';
        require_once 'modules/Leads/Leads.php';
        $seed_user = new Users();
        $user_id = $seed_user->retrieve_user_id($user_name);
        $current_user = $seed_user;
        $current_user->retrieve_entity_info($user_id, "Users");
        checkFileAccessForInclusion('user_privileges/user_privileges_' . $current_user->id . '.php');
        require 'user_privileges/user_privileges_' . $current_user->id . '.php';
        checkFileAccessForInclusion('user_privileges/sharing_privileges_' . $current_user->id . '.php');
        require 'user_privileges/sharing_privileges_' . $current_user->id . '.php';
        if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
            $sql1 = "select fieldname,columnname from vtiger_field where tabid=7 and block <> 14 and vtiger_field.presence in (0,2)";
            $params1 = array();
        } else {
            $profileList = getCurrentUserProfileList();
            $sql1 = "select fieldname,columnname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=7 and vtiger_field.block <> 14 and vtiger_field.displaytype in (1,2,4) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
            $params1 = array();
            if (count($profileList) > 0) {
                $sql1 .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")";
                array_push($params1, $profileList);
            }
        }
        $result1 = $adb->pquery($sql1, $params1);
        for ($i = 0; $i < $adb->num_rows($result1); $i++) {
            $permitted_lists[] = $adb->query_result($result1, $i, 'fieldname');
        }
        $Lead = new Leads();
        $Lead->column_fields[firstname] = in_array('firstname', $permitted_lists) ? $first_name : "";
        $Lead->column_fields[lastname] = in_array('lastname', $permitted_lists) ? $last_name : "";
        $Lead->column_fields[company] = in_array('company', $permitted_lists) ? $account_name : "";
        $Lead->column_fields[email] = in_array('email', $permitted_lists) ? $email_address : "";
        $Lead->column_fields[title] = in_array('title', $permitted_lists) ? $title : "";
        $Lead->column_fields[designation] = in_array('designation', $permitted_lists) ? $department : "";
        $Lead->column_fields[phone] = in_array('phone', $permitted_lists) ? $office_phone : "";
        $Lead->column_fields[homephone] = in_array('homephone', $permitted_lists) ? $home_phone : "";
        $Lead->column_fields[website] = in_array('website', $permitted_lists) ? $website : "";
        $Lead->column_fields[fax] = in_array('fax', $permitted_lists) ? $fax : "";
        $Lead->column_fields[mobile] = in_array('mobile', $permitted_lists) ? $phone_mobile : "";
        $Lead->column_fields[mailingstreet] = in_array('mailingstreet', $permitted_lists) ? $primary_address_street : "";
        $Lead->column_fields[mailingcity] = in_array('mailingcity', $permitted_lists) ? $primary_address_city : "";
        $Lead->column_fields[mailingstate] = in_array('mailingstate', $permitted_lists) ? $primary_address_state : "";
        $Lead->column_fields[mailingzip] = in_array('mailingzip', $permitted_lists) ? $primary_address_postalcode : "";
        $Lead->column_fields[workCountry] = in_array('mailingcountry', $permitted_lists) ? $workCountry : "";
        $Lead->column_fields[lane] = in_array('lane', $permitted_lists) ? $alt_address_street : "";
        $Lead->column_fields[city] = in_array('city', $permitted_lists) ? $alt_address_city : "";
        $Lead->column_fields[state] = in_array('state', $permitted_lists) ? $alt_address_state : "";
        $Lead->column_fields[code] = in_array('code', $permitted_lists) ? $alt_address_postalcode : "";
        $Lead->column_fields[country] = in_array('country', $permitted_lists) ? $alt_address_country : "";
        $Lead->column_fields[assigned_user_id] = in_array('assigned_user_id', $permitted_lists) ? $user_id : "";
        $Lead->column_fields[description] = "";
        //	$log->fatal($Lead->column_fields);
        $Lead->save("Leads");
        $Lead = $Lead;
        return $Lead->id;
    }
}
Ejemplo n.º 29
0
 public function getColumnsListbyBlock($module, $block, $pri_module, $current_user)
 {
     $adb = PearDatabase::getInstance();
     if (is_string($block)) {
         $block = explode(",", $block);
     }
     $tabid = getTabid($module);
     if ($module == 'Calendar') {
         $tabid = array('9', '16');
     }
     $params = array($tabid, $block);
     require 'user_privileges/user_privileges_' . $current_user->id . '.php';
     //Security Check
     if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
         $sql = "select * from vtiger_field where vtiger_field.tabid in (" . generateQuestionMarks($tabid) . ") and vtiger_field.block in (" . generateQuestionMarks($block) . ") and vtiger_field.displaytype in (1,2,3) and vtiger_field.presence in (0,2) ";
         //fix for Ticket #4016
         if ($module == "Calendar") {
             $sql .= " group by vtiger_field.fieldlabel order by sequence";
         } else {
             $sql .= " order by sequence";
         }
     } else {
         $profileList = getCurrentUserProfileList();
         $sql = "select * from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid in (" . generateQuestionMarks($tabid) . ")  and vtiger_field.block in (" . generateQuestionMarks($block) . ") and vtiger_field.displaytype in (1,2,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
         if (count($profileList) > 0) {
             $sql .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")";
             array_push($params, $profileList);
         }
         //fix for Ticket #4016
         if ($module == "Calendar") {
             $sql .= " group by vtiger_field.fieldid,vtiger_field.fieldlabel order by sequence";
         } else {
             $sql .= " group by vtiger_field.fieldid order by sequence";
         }
     }
     $result = $adb->pquery($sql, $params);
     $noofrows = $adb->num_rows($result);
     for ($i = 0; $i < $noofrows; $i++) {
         $fieldtablename = $adb->query_result($result, $i, "tablename");
         $fieldcolname = $adb->query_result($result, $i, "columnname");
         $fieldname = $adb->query_result($result, $i, "fieldname");
         $fieldtype = $adb->query_result($result, $i, "typeofdata");
         $uitype = $adb->query_result($result, $i, "uitype");
         $fieldtype = explode("~", $fieldtype);
         $fieldtypeofdata = $fieldtype[0];
         //Here we Changing the displaytype of the field. So that its criteria will be displayed correctly in Reports Advance Filter.
         $fieldtypeofdata = ChangeTypeOfData_Filter($fieldtablename, $fieldcolname, $fieldtypeofdata);
         if ($uitype == 68 || $uitype == 59) {
             $fieldtypeofdata = 'V';
         }
         if ($fieldtablename == "vtiger_crmentity") {
             $fieldtablename = $fieldtablename . $module;
         }
         if ($fieldname == "assigned_user_id") {
             $fieldtablename = "vtiger_users" . $module;
             $fieldcolname = "user_name";
         }
         if ($fieldname == "account_id") {
             $fieldtablename = "vtiger_account" . $module;
             $fieldcolname = "accountname";
         }
         if ($fieldname == "contact_id") {
             $fieldtablename = "vtiger_contactdetails" . $module;
             $fieldcolname = "lastname";
         }
         if ($fieldname == "parent_id") {
             $fieldtablename = "vtiger_crmentityRel" . $module;
             $fieldcolname = "setype";
         }
         if ($fieldname == "vendor_id") {
             $fieldtablename = "vtiger_vendorRel" . $module;
             $fieldcolname = "vendorname";
         }
         if ($fieldname == "potential_id") {
             $fieldtablename = "vtiger_potentialRel" . $module;
             $fieldcolname = "potentialname";
         }
         if ($fieldname == "assigned_user_id1") {
             $fieldtablename = "vtiger_usersRel1";
             $fieldcolname = "user_name";
         }
         if ($fieldname == 'quote_id') {
             $fieldtablename = "vtiger_quotes" . $module;
             $fieldcolname = "subject";
         }
         $product_id_tables = array("vtiger_troubletickets" => "vtiger_productsRel", "vtiger_campaign" => "vtiger_productsCampaigns", "vtiger_faq" => "vtiger_productsFaq");
         if ($fieldname == 'product_id' && isset($product_id_tables[$fieldtablename])) {
             $fieldtablename = $product_id_tables[$fieldtablename];
             $fieldcolname = "productname";
         }
         if ($fieldname == 'campaignid' && $module == 'Potentials') {
             $fieldtablename = "vtiger_campaign" . $module;
             $fieldcolname = "campaignname";
         }
         if ($fieldname == 'currency_id' && $fieldtablename == 'vtiger_pricebook') {
             $fieldtablename = "vtiger_currency_info" . $module;
             $fieldcolname = "currency_name";
         }
         $fieldlabel = $adb->query_result($result, $i, "fieldlabel");
         $fieldlabel1 = str_replace(" ", "_", $fieldlabel);
         $optionvalue = $fieldtablename . ":" . $fieldcolname . ":" . $module . "_" . $fieldlabel1 . ":" . $fieldname . ":" . $fieldtypeofdata;
         //$this->adv_rel_fields[$fieldtypeofdata][] = '$'.$module.'#'.$fieldname.'$'."::".vtranslate($module,$module)." ".$fieldlabel;
         //added to escape attachments fields in Reports as we have multiple attachments
         if ($module != 'HelpDesk' || $fieldname != 'filename') {
             $module_columnlist[$optionvalue] = vtranslate($fieldlabel, $module);
         }
     }
     $blockname = getBlockName($block);
     if ($blockname == 'LBL_RELATED_PRODUCTS' && ($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice')) {
         $fieldtablename = 'vtiger_inventoryproductrel';
         $fields = array('productid' => vtranslate('Product Name', $module), 'serviceid' => vtranslate('Service Name', $module), 'listprice' => vtranslate('List Price', $module), 'discount' => vtranslate('Discount', $module), 'quantity' => vtranslate('Quantity', $module), 'comment' => vtranslate('Comments', $module));
         $fields_datatype = array('productid' => 'V', 'serviceid' => 'V', 'listprice' => 'I', 'discount' => 'I', 'quantity' => 'I', 'comment' => 'V');
         foreach ($fields as $fieldcolname => $label) {
             $fieldtypeofdata = $fields_datatype[$fieldcolname];
             $optionvalue = $fieldtablename . ":" . $fieldcolname . ":" . $module . "_" . $label . ":" . $fieldcolname . ":" . $fieldtypeofdata;
             $module_columnlist[$optionvalue] = $label;
         }
     } elseif ($pri_module == "PriceBooks" && $blockname == "LBL_PRICING_INFORMATION" && ($module == "Products" || $module == "Services")) {
         $fieldtablename = "vtiger_pricebookproductreltmp" . $module;
         $fieldcolname = "listprice";
         $label = vtranslate("LBL_LIST_PRICE");
         //$customTmpLabel = "LBL@~@PB@~@LIST@~@PRICE";    // "@~@" stands for "_" that needs special handling because of translation of RB header
         $customTmpLabel = "LBL@~@LIST@~@PRICE";
         $fieldtypeofdata = "I";
         $optionvalue = $fieldtablename . ":" . $fieldcolname . ":" . $module . "_" . $customTmpLabel . ":" . $fieldcolname . ":" . $fieldtypeofdata;
         $module_columnlist[$optionvalue] = $label;
     }
     return $module_columnlist;
 }