コード例 #1
0
/**
 * Get PriceBook list
 * 
 * @param array $input_array    input data
 * @return array                resulted data
 */
function get_pricebooks_list($input_array)
{
    require_once 'modules/PriceBooks/PriceBooks.php';
    require_once 'include/utils/UserInfoUtil.php';
    global $adb, $log;
    global $current_user;
    require_once 'modules/Users/Users.php';
    $log->debug("Entering customer portal function get_pricebooks_list");
    $user = new Users();
    $userid = getPortalUserid();
    $show_all = show_all('PriceBooks');
    $current_user = $user->retrieveCurrentUserInfoFromFile($userid);
    $id = $input_array['id'];
    $only_mine = $input_array['onlymine'];
    $only_base = $input_array['onlybase'];
    $sessionid = $input_array['sessionid'];
    if (!validateSession($id, $sessionid)) {
        return null;
    }
    $entity_ids_list = array();
    if ($only_mine == 'true') {
        array_push($entity_ids_list, $id);
    } else {
        // TODO
    }
    $focus = new PriceBooks();
    $focus->filterInactiveFields('PriceBooks');
    foreach ($focus->list_fields as $fieldlabel => $values) {
        foreach ($values as $table => $fieldname) {
            $fields_list[$fieldlabel] = $fieldname;
        }
    }
    $FieldVisibilityByColumn = array();
    foreach ($fields_list as $fieldlabel => $fieldname) {
        $FieldVisibilityByColumn[$fieldname] = getColumnVisibilityPermission($current_user->id, $fieldname, 'PriceBooks');
    }
    // PriceBooks items selection
    $query = "SELECT * FROM vtiger_pricebook " . "INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_pricebook.pricebookid AND vtiger_crmentity.deleted = 0 " . "WHERE active = 1 ";
    if (count($entity_ids_list) > 0) {
        $query .= "AND owner_id IN (" . generateQuestionMarks($entity_ids_list) . ")";
    }
    $params = array($entity_ids_list);
    $res = $adb->pquery($query, $params);
    $noofdata = $adb->num_rows($res);
    for ($j = 0; $j < $noofdata; $j++) {
        $i = 0;
        foreach ($fields_list as $fieldlabel => $fieldname) {
            if (strcmp($fieldname, 'active') == 0) {
                continue;
            }
            $fieldper = $FieldVisibilityByColumn[$fieldname];
            if ($fieldper == '1') {
                continue;
            }
            $output[0]['head'][0][$i]['fielddata'] = $fieldlabel;
            $fieldvalue = $adb->query_result($res, $j, $fieldname);
            $pricebookid = $adb->query_result($res, $j, 'pricebookid');
            if ($fieldname == 'bookname') {
                $fieldvalue = '<a href="index.php?module=PriceBooks&action=index&fun=detail&pricebookid=' . $pricebookid . '">' . $fieldvalue . '</a>';
            }
            if ($fieldname == 'owner_id') {
                // TODO
            }
            $output[1]['data'][$j][$i]['fielddata'] = $fieldvalue;
            $i++;
        }
    }
    $log->debug("Exiting customer portal function get_pricebooks_list");
    return $output;
}