Display Dedicated IP into clientareainvoices.tpl list in WHMCS? - hook

I'm using WHMCS 8.x and Smarty PHP is already enabled.
I hope to use some code or hook function to let the dedicated ip or hostname to display on the page clientareainvoices.tpl (/clientarea.php?action=invoices) list .
I hope anyone can help me with this .
Thanks alot .
I have search a lot of plan , but all not working . I don't know whether this can be done with hook .
Hope someone of genius can help me about this .
the function like this in the picture .
enter image description here
thanks thanks thanks.
I tried to use a hook file to do this . and tried to connect the database tables use left join . like :
the file is like :
select * from tblinvoices t1
left join tblinvoiceitems t2 on t1.id=t2.invoiceid
left join tblhosting t3 on t2.relid=t3.id
WHERE t3.dedicatedIP = value
And I add this into the hook file .
<?php
if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
}
use WHMCS\Database\Capsule as DB;
add_hook('ClientAreaPageInvoices', 1, function($vars) {
$invoices = DB::table('tblinvoices')->where('invoicenum', $vars['invoicenum'])->get();
$fieldId = 'invoicenum';
$csVals = [];
foreach ($invoices as $invoice) {
$fieldVal = '';
$data = DB::table('tblinvoices AS t1')
->leftJoin('tblinvoiceitems AS t2', 't1.invoicenum', '=', 't2.invoiceid')
->leftJoin('tblhosting AS t3', 't2.relid', '=', 't3.id')
->select('t3.domain')
->where('t1.invoicenum', $fieldId)->where('t3.domain', $invoice['invoicenum'])
->first();
if (!is_null($data)) {
$fieldVal = $data->value;
}
$csVals[$invoice['invoicenum']] = $fieldVal;
}
return ['domain' => $csVals];
});
But all not working for this . it shows a result "Array" , hope anybody can hlep me . thanks in advance .

First you don't need to query invoices again, since the invoices are available in $vars['invoices'] variable.
$invoices = $vars['invoices'];
The code should work, you just need to edit the file clientareainvoices.tpl in your active template and replace:
<td>{$invoice.invoicenum}</td> with
<td>{$invoice.invoicenum} - {$domain[$invoice.invoicenum]}</td>

Related

Trying to delete sharpoint file with a "#" in the name

A lot of the documents I’m dealing with at the moment have a “#” in the file name and when listing the files in the folder I got around this issues by doing a simple replace of the encoded value of %25
var fileRefOriginal = file.ServerRelativeUrl;
var fileRef = fileRefOriginal.Replace("#", "%23");
var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(sourceContext, fileRef);
using (var fileStream = System.IO.File.Create(fileName))
{
fileInfo.Stream.CopyTo(fileStream);
}
But for some of the files I need to delete and I was just using this after the download;
sourceContext.Web.GetFileByServerRelativeUrl(fileRef).DeleteObject();
sourceContext.ExecuteQuery();
but it wasn’t removing anything and didn’t give an error so I tried this which just says file not found;
var f = sourceContext.Web.GetFileByServerRelativeUrl(fileRef);
sourceContext.Load(f);
f.DeleteObject();
sourceContext.ExecuteQuery();
I’ve tried it with the original name and the converted name (using %25) but seem to be getting no where.
Got this to work, by capturing the files unique ID, then instead of using ;
var f = sourceContext.Web.GetFileByServerRelativeUrl(fileRef);
I used this;
var f = sourceContext.Web.GetFileById(fileId);
Hope it helps someone with the same issue.

The ability to create Doc element of hypertext in Websharper.UI.Next

I have the string with html markup, an I want to cretae Doc elment from it like this:
Doc.FromHtm "<div><p>.....</p>.....</div>"
As I understand that this is not possible right now. Ok, what is not possible to accurately sew, I tried to roughly nail using jquery:
JQuery.JQuery.Of( "." + class'name ).First().Html(html'content)
But to call this code, I need to specify an event handler for the Doc element. But it is not implemented in UI.Next.
I tried to track changes of a model with a given CSS class asynchronously:
let inbox'post'after'render = MailboxProcessor.Start(fun agent ->
let rec loop (ids'contents : Map<int,string>) : Async<unit> = async {
// try to recive event with new portion of data
let! new'ids'contents = agent.TryReceive 100
// calculate the state of the agent
let ids'contents =
// merge Map's
( match new'ids'contents with
| None -> ids'contents
| Some (new'ids'contents) ->
new'ids'contents # (Map.toList ids'contents)
|> Map.ofList )
|> Map.filter( fun id content ->
// calculate CSS class name
let class'name = post'text'view'class'name id
// change it's contents of html
JQuery.JQuery.Of( "." + class'name ).First().Html(content).Size() = 0)
// accept the state of the agent
return! loop ids'contents }
loop Map.empty )
and then, for example for one element:
inbox'post'after'render.Post [id, content]
But it is too difficult, unreliable and not really working.
Please give me an idea how to solve the problem if possible. Thanks in advance!
Just in case someone needs to use static HTML in WebSharper on the server (I needed to add some javascript to the WebSharper generated HTML page), there is fairly new Doc.Verbatim usable e.g. like
let Main ctx action title body =
Content.Page(
MainTemplate.Doc(
title = title,
menubar = MenuBar ctx action,
body = body,
my_scripts = [ Doc.Verbatim JavaScript.Content ]
)
)
Already answered this on https://github.com/intellifactory/websharper.ui.next/issues/22 but copying my answer here:
If all you want is to create a UI.Next Doc from static html you can do the following:
let htmlElem = JQuery.JQuery.Of("<div>hello</div>").Get(0)
let doc = Doc.Static (htmlElem :?> _)
This is not very nice but should work and I don't think there's a better way to do it at the moment. Or maybe you could use templating but that's not documented yet and I'm not sure it would fit your use case.
Obviously if you want to change the rendered element dynamically you can make it a Var and use Doc.EmbedView together with Doc.Static.

Specify a page for pagination - Laravel 4

I'm trying to "remember" the page the user was on as he browses through records so that when he returns to the list, he is returned to the page where he left off.
How do I change the "current page" value for paginator?
I've tried Input::set('page', $x); but there's no such function.
$_GET['page'] = $x; doesn't work too.
This the code:
$list = Publication::orderBy($this->data['sort_by'], $this->data['order_by']);
foreach ($this->data['filter_data'] AS $field => $value) {
$list->where($field, 'LIKE', "%$value%");
}
$this->data['list'] = $list->paginate(15);
I looked at the API --- turns out this is much easier now in 2014.
All you have to do is set
Paginator::setCurrentPage(2);
any time before you call ->paginate(), I believe, and it should override the page set (or not set) by ?page=.
You can adjust the page of the pagination environment through the DB connection.
DB::getPaginator()->setCurrentPage(2);
Not entirely sure but you might be able to go through your model with something like this.
Publication::getConnection()->setCurrentPage(2);
If the above isn't working (as it seems from your comment), then do it with an instance of Publication.
$publication = new Publication;
$publication->getConnection()->setCurrentPage(2);
$list = $publication->orderBy(...);
Try
$pager->setCurrentPage(2);

Zend_Search_Lucene - weird behaviour for Wildcard search and "numeric" string

Weird issue I get every time I search "11.11" or "22.22" etc... No problem if I search for "aa.aa" but when I put only integers into my string, I get the following exception:
Wildcard search is supported only for non-multiple word terms
My implementation of Zend search is as below (ZF 1.11):
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0);
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(
new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive()
);
$index = Zend_Search_Lucene::open(APPLICATION_PATH.'/../var/search');
if(str_word_count($searchQuery) > 1){
$searchQuery = Zend_Search_Lucene_Search_QueryParser::escape($searchQuery);
$searchQueryArray = explode(' ', $searchQuery);
$query = new Zend_Search_Lucene_Search_Query_Phrase($searchQueryArray);
}else{
$searchQuery = Zend_Search_Lucene_Search_QueryParser::escape($searchQuery);
$query = Zend_Search_Lucene_Search_QueryParser::parse(
'title:*'.$searchQuery.'* OR
description:*'.$searchQuery.'* OR
content:*'.$searchQuery.'*'
);
}
$result = $index->find($query);
I can't really find any related issue on internet so please, let me know if you've ever been in front of the similar issue. Thank you.

How to add a Calculated field to AllContentType?

Today, I'm having a problem is after I had created a Calculated field. It seems there is no way to add AllContentTypes. And the DefaultView, maybe I can handle this. And I also saw this method:
spList.Fields.AddFieldAsXml(spFieldUser.SchemaXml, True, SPAddFieldOptions.AddToAllContentTypes);
But in this case, I'm not sure I can use it or not. Because my code is:
//SPField tempSPField = spList.Fields.CreateNewField(createSPColumnObject.ColumnType, createSPColumnObject.ColumnName);//We can not use this code line for creating Calculated (there is no constructor for this)
SPFieldCollection collFields = spList.Fields;
string strSPFieldCalculatedName = collFields.Add(createSPColumnObject.ColumnName, SPFieldType.Calculated, false);
if (createSPColumnObject.IsAddedToDefaultView)
{
SPView spView = spList.DefaultView;
spView.ViewFields.Add(strSPFieldCalculatedName);
spView.Update();
}
SPFieldCalculated spFieldCalculated = null;
//
spFieldCalculated = (SPFieldCalculated)collFields[createSPColumnObject.ColumnName];
spFieldCalculated.ShowInDisplayForm = true;
//spFieldCalculated.ShowInEditForm = true;
spFieldCalculated.ShowInListSettings = true;
//spFieldCalculated.ShowInNewForm = true;
spFieldCalculated.ShowInViewForms = true;
//
spFieldCalculated.Description = createSPColumnObject.ColumnDescription;
spFieldCalculated.Formula = string.Format(#"={0}",createSPColumnObject.CalcFormula);
spFieldCalculated.Update();
//spList.Fields.AddFieldAsXml(spFieldCalculated.SchemaXml, createSPColumnObject.IsAddedToDefaultView, SPAddFieldOptions.AddToAllContentTypes);// also use this code line because we will get an exception with a duplicate column ID.
spFieldCalculated.OutputType = SPFieldType.Text;
spList.Update();
I totally created a Calculated column but how can I add it to allcontent types ? everybody could help me out this ? BTW, to the DefaultView, I did like the above is right ? Could eveybody let me know this ?
I just worry about everybody get misunderstanding ? Or review with missing code. So could everybody please to take a look on my code clearly ? Thanks all.
Many thanks, :)
Standley Nguyen
I'm not sure if i fully understand what you are trying to do however i may be able to shed some light on some parts of what you are trying to do.
When you create your field does it then appear in your site actions -> site settings -> Site columns. If so you have created this correctly. If it doesn't there are hundreds of examples of how to do this if you search google.
Once you have your field create you then need to consider which content types you want to add it to. Once you have these content types you then have to add something called a field link to the Content type.
This isn't my code i have picked it off the web but this should do what you require.
SPContentType ct = web.ContentTypes[contentType];
ct.FieldLinks.Add(new SPFieldLink(field));
ct.Update();
Cheers
Truez

Resources