Would you please help me how to implement the below code in codeignitor ( In View Files )
If(Language = "English "){
echo " 1 " ;
}
else{
Echo " 2 ";
|
Because I want to use the conditions to load some files for each language on the website such as CSS and other files.
I appreciate your help.
If( $this->session->userdata('language') == "English "){
echo " 1 " ;
}
else{
Echo " 2 ";
|
it's return application current language
https://codeigniter.com/user_guide/libraries/language.html
Related
With the upgrade to Magento 2.4.5 from 2.4.2, the old code in an observer class in a custom module to get information about Stripe Payment isn't working any more. It looks like Magento event sales_order_place_after isn't able to help with retrieving payment information. I tried several other events including sales_order_load_after sales_order_save_before sales_order_save_after sales_order_delete_before sales_order_delete_after and checkout_submit_all_after.
Below is a part of the test program:
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
// Initial code to Bootstrap Magento 2 ends here
/*************************************************************************************************/
$date = $timezone->date();
// If one needs to diplay date in the formate of Ymd use 'Ymd'
$current_store_time = $date->format('Ymd H:i:s');
echo "<body>";
echo "**********************************************Magento Store Time : " . $current_store_time . "**********************************<br><br>";
// Sanitize the $_GET[] value
// redirect if the message parameter is invalid.
if (isset($_GET["order_id"])) {
if (htmlspecialchars($_GET["order_id"]) == "invalid_id") {
echo "Please ensure to enter the valid order ID by replacing invalid_id` with valid order ID in the URL";
exit;
}
}
// Sanitize the $_GET[] value
// Create an object of the order loaded with the $order_id passed as query string.
$orderId = htmlspecialchars($_GET["order_id"]);
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementID($orderId);
if ($order->getEntityId()) {
echo "*********************************************Get Order Information: " . '*************************************************<br>';
echo "Entity ID: " . $order->getEntityId() . '<br>';
echo "Increment ID: " . $order->getIncrementId() . '<br>';
echo "State: " . $order->getState() . '<br>';
echo "Status: " . $order->getStatus() . '<br>';
echo "Store ID: " . $order->getStoreId() . '<br>';
echo "Grand Total: " . $order->getGrandTotal() . '<br>';
echo "SubTotal: " . $order->getSubtotal() . '<br>';
echo "Total Quantity" . $order->getTotalQtyOrdered() . '<br>';
echo "Currency Code: " . $order->getOrderCurrencyCode() . '<br><br>';
echo "Discout Applied: " . $order->getDiscountAmount() . '<br><br>';
// Get Customer Information from the Order
echo "Get Customer Information: " . "<br>";
echo "Customer Email : " . $order->getCustomerEmail() . '<br><br>';
echo "<br><b>**********************Testing with getAllVisibleItems() function call************</b><br>";
//error_log(print_r($order->getAllVisibleItems()));
$orderItems = $order->getAllVisibleItems();
foreach ($orderItems as $orderItem) {
echo ("SKU = " . $orderItem->getSku() . "<br>");
echo ("Name = " . $orderItem->getName() . "<br>");
echo ("Price = " . $orderItem->getPrice() . "<br>");
echo ("Qty = " . $orderItem->getQtyOrdered() . "<br>");
}
echo "<br>";
// Get Order Payment Information
echo "Get Payment Information: " . "<br>";
$payment = $order->getPayment();
$stripePayment = $objectManager->get('\Magento\Sales\Model\Order\Payment');
$this->logger->debug("CC Last 4 digits " . $stripePayment->getCcLast4());
How can I create map, a higher order function, in Red language. It should take a block and a function as arguments and apply the sent function to each member of block. I tried following code:
Red []
mapfn: function[blk sfn][
outblk: copy []
foreach i blk[
append outblk (sfn i) ]
outblk ]
; to test:
myblk: [" this " " is " " a " " line " "for" " testing " " only "]
probe mapfn myblk 'reverse
probe mapfn myblk 'trim
But it is not working - it simply sends back the original block without changing it or giving any error message. How can this be corrected?
In Rebol you have the mezzanine function apply
>> help apply
USAGE:
APPLY func block /only
DESCRIPTION:
Apply a function to a reduced block of arguments.
APPLY is a function value.
ARGUMENTS:
func -- Function value to apply (Type: any-function)
block -- Block of args, reduced first (unless /only) (Type: block)
REFINEMENTS:
/only -- Use arg values as-is, do not reduce the block
(SPECIAL ATTRIBUTES)
throw
See source apply.
As long as Red has no native apply you can write your own mapping function e.g
mapfn: function[blk sfn][
outblk: copy []
foreach i blk[
append outblk sfn copy i
]
outblk
]
Get the function with :functionname
>> myblk: [" this " " is " " a " " line " "for" " testing " " only "]
== [" this " " is " " a " " line " "for" " testing " " only "]
>> probe mapfn myblk :reverse
[" siht " " si " " a " " enil " "rof" " gnitset " " ylno "]
== [" siht " " si " " a " " enil " "rof" " gnitset " " ylno "]
>> probe mapfn myblk :trim
["this" "is" "a" "line" "for" "testing" "only"]
== ["this" "is" "a" "line" "for" "testing" "only"]
>>
An alternative and better way as you can not copy all datatypes is e.g.
mapfn: function[blk sfn][
collect [
foreach i blk[
keep sfn i
]
]
]
and call the function this way if no do not want to modify the original
mapfn newblk: copy/deep myblk :reverse
This question already has answers here:
Using box-drawing Unicode characters in batch files
(3 answers)
Closed 3 years ago.
a while ago i were googling to find out how I could make a batch menu with a more "professional look" instead of using symbols such as:
|=====|
|-----|
|_____|
to make outlines around a menu in batch.
but I had no luck.
today i randomly found this article:
https://web.archive.org/web/20151204182221/https://http-server.carleton.ca/~dmcfet/menu.html
and it explains that by using ms-dos (edit.com) I can do this.
but as my computer is a 64 bit win 10. I dot have the edit.com so.... how could I make this kind of menu look by hand? (printing special characters shown on left side of the header "STEP 3, Lines, Lines, Lines.")
Here's a batch + PowerShell menu maker I've been working on. Set the values in the batch portion, and the PowerShell stuff will auto resize and reposition as needed. When a selection is made, the console buffer restores its former contents, effectively vanishing the menu.
It looks like this:
Here's the code. Save it with a .bat extension.
<# : Batch portion
#echo off & setlocal enabledelayedexpansion
set "menu[0]=Format C:"
set "menu[1]=Send spam to boss"
set "menu[2]=Truncate database *"
set "menu[3]=Randomize user password"
set "menu[4]=Download Dilbert"
set "menu[5]=Hack local AD"
set "default=0"
powershell -noprofile "iex (gc \"%~f0\" | out-string)"
echo You chose !menu[%ERRORLEVEL%]!.
goto :EOF
: end batch / begin PowerShell hybrid chimera #>
$menutitle = "=== MENU ==="
$menuprompt = "Use the arrow keys. Hit Enter to select."
$maxlen = $menuprompt.length + 6
$menu = gci env: | ?{ $_.Name -match "^menu\[\d+\]$" } | %{
$_.Value.trim()
$len = $_.Value.trim().Length + 6
if ($len -gt $maxlen) { $maxlen = $len }
}
[int]$selection = $env:default
$h = $Host.UI.RawUI.WindowSize.Height
$w = $Host.UI.RawUI.WindowSize.Width
$xpos = [math]::floor(($w - ($maxlen + 5)) / 2)
$ypos = [math]::floor(($h - ($menu.Length + 4)) / 3)
$offY = [console]::WindowTop;
$rect = New-Object Management.Automation.Host.Rectangle `
0,$offY,($w - 1),($offY+$ypos+$menu.length+4)
$buffer = $Host.UI.RawUI.GetBufferContents($rect)
function destroy {
$coords = New-Object Management.Automation.Host.Coordinates 0,$offY
$Host.UI.RawUI.SetBufferContents($coords,$buffer)
}
function getKey {
while (-not ((37..40 + 13 + 48..(47 + $menu.length)) -contains $x)) {
$x = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown').VirtualKeyCode
}
$x
}
# http://goo.gl/IAmdR6
function WriteTo-Pos ([string]$str, [int]$x = 0, [int]$y = 0,
[string]$bgc = [console]::BackgroundColor, [string]$fgc = [Console]::ForegroundColor) {
if($x -ge 0 -and $y -ge 0 -and $x -le [Console]::WindowWidth -and
$y -le [Console]::WindowHeight) {
$saveY = [console]::CursorTop
$offY = [console]::WindowTop
[console]::setcursorposition($x,$offY+$y)
Write-Host $str -b $bgc -f $fgc -nonewline
[console]::setcursorposition(0,$saveY)
}
}
function center([string]$what) {
$what = " $what "
$lpad = " " * [math]::max([math]::floor(($maxlen - $what.length) / 2), 0)
$rpad = " " * [math]::max(($maxlen - $what.length - $lpad.length), 0)
WriteTo-Pos "$lpad $what $rpad" $xpos $line blue yellow
}
function menu {
$line = $ypos
center $menutitle
$line++
center " "
$line++
for ($i=0; $item = $menu[$i]; $i++) {
# write-host $xpad -nonewline
$rtpad = " " * ($maxlen - $item.length)
if ($i -eq $selection) {
WriteTo-Pos " > $item <$rtpad" $xpos ($line++) yellow blue
} else {
WriteTo-Pos " $i`: $item $rtpad" $xpos ($line++) blue yellow
}
}
center " "
$line++
center $menuprompt
1
}
while (menu) {
[int]$key = getKey
switch ($key) {
37 {} # left or up
38 { if ($selection) { $selection-- }; break }
39 {} # right or down
40 { if ($selection -lt ($menu.length - 1)) { $selection++ }; break }
# number or enter
default { if ($key -gt 13) {$selection = $key - 48}; destroy; exit($selection) }
}
}
FIX:
in order to create a menu like this. you will need to use an editor such as notepad++
open a new notepad ++ file. then goto format and select western europe OEM-US charset.
then simply go here: https://en.wikipedia.org/wiki/Box-drawing_character
and copy paste the symbols you want for your menu in notepad++ and save.
example:
Displayed in notepad++ :
echo ╔════════════════════════════╗
echo ║Bill register/database Menu ║
echo ╠════════════════════════════╣
echo ║ 1. -Register a bill ║
echo ║ 2. -Check Bill Info ║
echo ║ 3. Set payment ║
echo ╚════════════════════════════╝
displayed in normal notepad :
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo ºBill register/database Menu º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º 1. -Register a bill º
echo º 2. -Check Bill Info º
echo º 3. Set payment º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
so as you can see. it works with normal notepad too. but its easier to work with it in notepad++ as it displays what it actually look like.
It's not necessary to worry about code pages or file encodings at all.
When you are on windows 10 you can use the Character Set - DEC Line Drawing Mode
This uses ansi-escape sequences to show borders.
The border characters are represented by the characters jklmnqtuvwx.
for /F "delims=#" %%E in ('"prompt #$E# & for %%E in (1) do rem"') do set "\e=%%E"
REM *** Enable DEC Line Drawing Mode
echo %\e%(0
echo lqqk
echo x x
echo x x
echo mqqnqqk
echo x x
echo mqqj
REM *** Enable ASCII Mode (Default)
echo %\e%(B
The output is
┌──┐
│ │
│ │
└──┼──┐
│ │
└──┘
for Notepad with ASCII and CHCP 1250 / CHCP 1252 characters are:
É Í » ş Č Ľ
I am using AutoHotKey to build a simple GUI tool that uses the Sysinternals tool PSLoggedOn. First if I use
run psloggedon.exe -l -x \\computername I don't get any output at all.
So I tried run %ComSpec% /C psloggedon.exe -l -x 1> %Temp%\psloggedon.txt and that gives me the output in domain\username format for each user logged in.
Like my first example I would rather just run psloggedon and get the output instead of first opening a command prompt; is that possible somehow?
Either way I want to take the output and avoid writing it to a file, but instead edit the output from the output stream to remove the "domain\" part and then just return the username. How can this be done without any third-party software?
This answer to another question on Serverfault shows a way to do it by reading the StdoutRead.
I too was looking at a way to avoid using a file but have decided it's actually the simplest option.
Code copied from user60738
#include <Constants.au3>
Dim $line, $line2, $file, $icount, $reg, $reg2, $reg3
$file = FileOpen("pclist.txt", 0)
While 1
$line = FileReadLine($file)
If #error Then ExitLoop
$reg3 = ""
$reg2 = ""
$reg = ""
If Ping($line, 200) Then
$reg = #ComSpec & ' /C "' & #ScriptDir & "\pstools\psloggedon.exe -l -x \\" & $line & '"'
$reg = Run($reg, "", #SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD)
While 1
$reg2 = StdoutRead($reg)
If #error Then ExitLoop
If $reg2 Then
$reg3 &= $reg2
EndIf
WEnd
If StringInStr($reg3, "Error") Then
$reg = "Error"
ElseIf StringInStr($reg3,"No one is logged") Then
$reg = "No one is logged on locally."
Else
$reg = StringTrimLeft($reg3, StringInStr($reg3, Chr(13), "", 3))
$reg = StringTrimLeft($reg, StringInStr($reg, "\"))
$reg = StringTrimRight($reg, StringLen($reg) - StringInStr($reg, Chr(13)))
$reg = StringStripWS($reg, 8)
EndIf
$icount += 1
$line2 &= $icount & #TAB & $line & #TAB & $reg & #CRLF
EndIf
TrayTip("Psloggedon", $icount & " " & $line & " User: " & $reg, 10)
WEnd
FileClose($file)
ConsoleWrite($line2)
FileDelete("C:\output.txt")
FileWrite("C:\output.txt", $line2)
ShellExecute("C:\output.txt")
I've got a CSV-file from HR with aprox 1000 lines (employees) that I feed to AD with Powershell.
This works, but I am a bit uncertain if I am doing this the right way.
This are my major concerns:
I am setting the attributes one at a time. Should I put the "changes" into an some kind of array/hasthable/object and do it all at once at the end of the script? But How? "New-Object"?
Should I use functions? But how can I return values (and continue based on the result from the function)?
All programming hints, corrections would be GREATLY appreciated. I really understand this wonderful community of knowledgable people so, let me have it. If you have the time please tell me how I can do this better..
This is my code:
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin -ErrorAction silentlycontinue
Add-PSSnapin quest.activeroles.admanagement -ErrorAction silentlycontinue
$file = "\Scripts\employees.csv" # Location of the input file
$file2 = "\Scripts\employees2.csv" # Temp file
$logfile = "\Scripts\logfile.txt" # log file
remove-item $logfile -Force -ErrorAction SilentlyContinue
Get-Content $file | Out-File -Encoding UTF8 $file2 # Convert to UTF8 (we don't touch the original inputfile)
$ListEmployees = Import-Csv $file2 -Delimiter ";" # Import the file to CSV
foreach ($ListEmployee in $ListEmployees) {
$ListDisplayName = $ListEmployee.firstname + " " + $ListEmployee.lastname
if($ADemployee = Get-QADUser -displayname $ListDisplayName -IncludedProperties employeeid )
{
## CHECK NAME
if($($ADEmployee.displayname) -eq $($ListDisplayName))
{
echo "MATCH: $($ADEmployee.displayname)"
}
## CHECK COMPANY
if($($ADEmployee.company) -ne $($ListEmployee.company))
{
echo " CHANGE - Company: '$($ADEmployee.company)' to '$($ListEmployee.company)'"
Set-QADUser -identity $($ADEmployee.samaccountname) -Company $($ListEmployee.company) -WhatIf
}
else
{
echo " OK - Company : no change '$($ListEmployee.company)'"
}
## CHECK OFFICE
if($($ADEmployee.office) -ne $($ListEmployee.office))
{
echo " CHANGE - Office '$($ADEmployee.office)' to '$($ListEmployee.office)'"
Set-QADUser -identity $($ADEmployee.samaccountname) -Office $($ListEmployee.Office) -WhatIf
}
else
{
echo " OK - Office : no change '$($ListEmployee.office)'"
}
## CHECK MOBILE
if( $listemployee.mobile -match '\S' )
{
if($($ADEmployee.mobile) -ne $($ListEmployee.mobile))
{
echo " CHANGE - Mobile : '$($ADEmployee.mobile)' to '$($ListEmployee.mobile)'"
Set-QADUser -identity $($ADEmployee.samaccountname) -Mobile $($ListEmployee.mobile) -WhatIf
}
else
{
echo " OK - Mobile : no change '$($ListEmployee.mobile)'"
}
}
## CHECK EMPLOYEEID
if($($ADEmployee.employeeid) -ne $($ListEmployee.employeeid))
{
echo " CHANGE - EmployeeID: '$($ADEmployee.employeeid)' to '$($ListEmployee.employeeid)'"
Set-QADUser -identity $($ADEmployee.samaccountname) -ObjectAttributes #{employeeID = $($ListEmployee.employeeid)} -WhatIf
}
else
{
echo " OK - EmployeeID : no change '$($ListEmployee.employeeid)'"
}
$match++
}
else
{
if($EXContact = Get-Contact $ListDisplayName -ErrorAction SilentlyContinue)
{
echo "MATCH CONTACT: $ListDisplayName (contact)"
## CHECK MOBILE
if( $listemployee.mobile -match '\S' )
{
if($($EXContact.Mobilephone) -ne $($ListEmployee.mobile))
{
echo " CHANGE - Mobile : '$($EXContact.Mobilephone)' to '$($ListEmployee.mobile)'"
}
else
{
echo " OK - Mobile ; No change ($($ListEmployee.mobile))"
}
}
## CHECK COMPANY
if($($EXContact.company) -ne $($ListEmployee.company))
{
echo " CHANGE - Company: '$($EXContact.company)' to '$($ListEmployee.company)'"
}
else
{
echo " OK - Company : No change($($ListEmployee.company))"
}
## CHECK OFFICE
if($($EXContact.office) -ne $($ListEmployee.office))
{
echo " CHANGE - Office '$($EXContact.office)' to '$($ListEmployee.office)'"
}
else
{
echo " OK - Office : No Change($($ListEmployee.office))"
}
$contactmatch++
}
else
{
echo "$ListDisplayName" | Out-File $logfile -Append
echo "NO MATCH: $ListDisplayName"
$nomatch++
}
}
$i++
}
echo " "
echo "List contains $i accounts"
echo "Accounts: $match matches"
echo "Contacts: $contactmatch"
echo "No Match: $nomatch"
And; If you think this is cr*p, tell me! I'd rather hear it from you than you staying silent just to be polite! I am "quite" new to this so I deserve it:)
Something that seems odd about the whole thing is using display name as your identity reference. As an identity reference, it't both volatile and potentially ambiguos in AD, and seems a poor choice to use to drive a maintenance script.
Here is my opinion :
1) I really think that the problem #mjolinor point is important, and you will meet troubles (I mean need human check) if you don't use one of the identity attributes fixed by Microsoft (samAccountName, userPrincipalName or better objectGuid, objectSid ...) as a key to find your users in Active-Directory.
If it's not possible you perhaps can buid a filter on the top of multiples attributes. If you CSV comes from another LDAP Directory you perhaps can integrate their unique ID in you Schema (in this case see Microsoft Services for UNIX 3.5 (MSFU3.5) schema extensions to Active Directory).
2) Once you find one of your CSV entry in your Active-Directory, you check each attributes, and then replace 'one by one' the ones in your AD with the one in your CSV.
Here my advice will be to check all the differencies between your CSV and AD entry, and them made an unique change into the Directory. In fact, on one différence, I will change them all in one command. I don't know how Set-QADUser is written, but in the low level layers all the attributes replacement can be made one shot (LDAP_REPLACE, or in a single ADSI commit)
3) Just a remark : begining PowerShell V2 (Seven, W2K8) an Active-Directory module is given by Microsoft.