TBS (TinyButStrong) get last value - php

I have a Word template, where I go through a TBS block and dynamically display the values. Now I'd like to compare the actual value with the last value displayed. Is there any possibility to solve this in word?
I was thinking of setting a variable and save the last value in this variable. So I only have to compare my own variable with the actual value. But I cant figure out, whether this is possible or not. Any help or other suggestions?
Example
*[myblock;block=begin]
[myblock.entry] // here I want to check if its the same as the last entry
[myblock;block=end]*

TinyButStrong cannot do that in native.
But you can use parameter « ondata » and a PHP user function in order to add the previous value in the current record.
You can also use a method of an object (see TBS documentation)
PHP :
function f_ondata_user($BlockName, &$CurrRec, $RecNum) {
static $entry_prev = '';
$CurrRec['entry_prev'] = $entry_prev;
$entry_prev = $CurrRec['entry'];
}
Template :
*[myblock;block=begin;ondata=f_ondata_user]
[myblock.entry]
[myblock.entry_prev] // here I want to check if its the same as the last entry
[myblock;block=end]*

Related

Create session variable from mysql column parameter

I am trying to create a php session variable which should reference "language":"ENG" (and more specifically ENG) within the table column params.
Example: Originally I've been using a "userLanguage" column and created my php session variable like this:
$_SESSION['userLanguage'] = $result[0]['userLanguage'];
Since "language":"ENG" is only one part of the field's value ({"admin_style":"","admin_language":"","language":"ENG","editor":"","helpsite":"","timezone":""}), this obv. doesn't work anymore. Is there an easy way to pull ENG from language? Help would be much appreciated.
Simply run a json_decode() on the field value.
$params = json_decode($result[0]['params']);
if(isset($params->language)){
$_SESSION['userLanguage'] = $params->language;
}

OpenTBS multiply variable with other variable inside table

I am trying to use the following functionality:
[quote_elements.product.factor;ope=mul:quote_elements.qty]
But all I get is always 0.
if I use:
[quote_elements.product.factor;ope=mul:4]
it works fine and I get 4 times the factor number.
But this is not what I need. I need to multiply dynamically the factor with the quantity. this can be for each row different.
any tips what I am missing here?
Embedded TBS fields does not work in parameter ope.
That why the string « quote_elements.qty » is always converted to 0.
Parameter ope=mul can work only with fixed values.
In order to solve you problem, you can use a custom ondata function. It will enable you to add a calculated column in you record before to merge it.
PHP side:
function f_my_ondata($BlockName, &$CurrRec, $RecNum) {
$CurrRec['my_result'] = $CurrRec['product']['factore'] * $CurrRec['qty'];
}
Template side :
[quote_elements;block=...;ondata=f_my_ondata] // block definition
...
[quote_elements.my_result]

Use a loop to look through POST variables

I'm trying to make a POST method that will receive a value from a table (that is dynamically generated). This value will be equal to a company name, and a hidden field will be there that is equal to company name + "id" appended to it.
Here's my code:
if(isset($_POST))
{
foreach ( $users as $balance_user ) {
if(isset($_POST[$balance_user]))
{
//update user meta with new balance
$newBalance = $_POST[$balance_user];
$postedID = $_POST[$balance_user.'id'];
update_user_meta($postedID, 'balance', $newBalance);
}
}
}
I keep getting the error Illegal offset type in isset or empty. Can I not pass variables in that way? For example if a company is called Acme, and that particularly named input has a value in it, I want to loop through all of the companies in the POST method, and if that part of the loop equals the company passed in the variable, it should do something.
Add these three lines to see the data, as others have indicated, clearly you are assuming some value is in $balance_user which is not there, or is different.
echo '<pre>:';
var_dump($balance_user);
echo ':</pre>';
if(isset($_POST[$balance_user]))
The pre makes it easier to read the debugging output. the :..: will show null values.
Once you run that, you will probably discover that one of your entries in $users is empty.
The output order will show you where that empty user value is.
However:
$postedID = $_POST[$balance_user.'id'];
That could be the error source as well, is there a post value that is. say, $balance_user == fred
fredid
if there isn't, of course you will instantly get that error. You aren't giving the line number of the error so I can't tell which it is, the line number will show it instantly.

Session array accessing on next button click of next button

How to get next array element from session array on next button click?
I tried next($_SESSION['qid']) it didn't work
if((int)$_SESSION['qn']<=20) {
$_SESSION['qn']=$_SESSION['qn']+1;
$_SESSION['qid']++;
}
I also tried
$_SESSION['qid']=next($_SESSION['qid']);
But this neither worked. Can someone help me?
_SESSION array is an associative array. You can't access it by numeric index, but you must specify the index name (e.g. in your code, $_SESSION['qid']). Anyway, you can still use next() function, passing the array $_SESSION (see here: http://php.net/manual/en/function.next.php). The correct way to use it is:
$element = next($_SESSION)
you'd likely want to put this code in a cycle.
Additionally, your code:
$_SESSION['qn']=$_SESSION['qn']+1;
means: assign to $_SESSION['qn'] the value of $_SESSION['qn'] plus 1, which is not what you want.
In case you'd want the next element in a NON associative array, you should use:
$arr = $arr[$i+1]
where $i is a integer value.
Update: regarding your comment, why don't you save a regular array (non associative) inside $_SESSION['questions']? This way you'd have the questions accessible this way:
$_SESSION['questions'][0], $_SESSION['questions'][1]...
Now you can use it within a cycle, or whatever you want. E.g.:
echo $_SESSION['questions'][$current_question_id+1];
where $current_question_id would be the current question index, which will be updated (+1) every clic on the next button

drupal---theme code

$i = 0;
$suggestion = 'page';
$suggestions = array();
while ($arg = arg($i++)) {
$arg = str_replace(array("/", "\\", "\0"), '', $arg);
$suggestions[] = $suggestion . '-' . $arg;
if (!is_numeric($arg)) {
$suggestion .= '-' . $arg;
}
}
i am a newbie of drupal,i can't follow the above code well, hope someone can explain it to me.i know the first line is assign the 0 to $i,then assign 'page' to an array. and i know arg is an array in drupal.
for example, now the url is example.com/node/1. how to use this url to use the above code.
It looks like its purpose is to generate ID strings (probably for a CSS class) depending on paths and excludes numeric components of the path out of the generated ID.
For example, 'my/123/article' produces the ID "page-my-article".
It seems this comes from a function (because the loop reads parameters using arg()) and that it expects Drupal paths such as "node/123/edit".
So the function would be called something like that:
mystery_function("my/123/article", "even/better/article");
Variables:
$i is the variable that stores the loop index
$suggestion is a String that store the generated ID. It is initialized to "page" because the ID is meant to have the syntax "page-SOMETHING".
$arg comes from the while loop: it reads the parameters passed to the mystery function one by one
$suggestions is an array that contains the generated IDs, one per argument passed to the mystery function.
In the loop:
The "$arg = str_replace..." line removes unwanted characters like "\" (however that line could definitely be improved).
The "$suggestions[] = ..." line adds the ID to the array of results.
The "if (!is_numeric($arg)..." line excludes numbers from the generated ID (e.g. "my/123/article" is probably supposed to produce "my-article")
The "$suggestion .= ..." line appends the value of "$arg" to the value of "$suggestion" and stores it in "$suggestion"
But honestly, I wouldn't advise to use that code: I doubt it works as intended given $suggestion isn't reinitialized at each loop so the value of the first path will get attached to the second, and to the third, and so on, and I doubt that is intentional.
Most likely this code is located in a theme's template.php in the preprocess_page hook. If that is the case, it's used to create template suggestions based on an argument supplied like the node id, to make it possible to create a page template per node.
What this code does, is that it loops though all the arguments in the drupal url, This could be user/3, node/3, taxonomy/term/3 or any custom url.
It first does some cleanup in the argument, to make sure that no weird symbols is added. This is not needed for most urls, but is probably there as a safety to avoid needing to have to create weird template names in some cases. This is done with str_replace
Next it adds the a suggestion to the list, based on the arg.
If the arg isn't numeric it adds that to the suggestion so it will be used in the next loop.
The idea is that you with the above urls will get added some template suggestions that look like this:
page
page-user
page-user-3
And
page
page-taxonomy
page-taxonomy-term
page-taxonomy-term-3
In this list drupal will use the last one possible, so if page-user-3.tpl.php exists, that will be used as page template for user/3, if not page-user.tpl.php will be used and so on.
This can be desired if you want to create customize page templates for the users page, or the nodes page while being able to create customized page templates for specific users.
This is not, however, a strategy I would want to employ. If you do this, you will end of with lots of different versions of a page template, and it will end up creating the maintenance nightmare that CMS systems was supposed to eliminate. If you truly need this many different page templates, you should instead look at context or panels, and put some logic into this instead.

Categories