Jump to content

convert date from Gregorian to Solar(Jalali)


mohammad50

Recommended Posts

hi

at version 5 of whmcs for converting dates from Gregorian to solar(Jalali) in viewinvoice.tpl file

 

first i add this line at top of viewinvoice.tpl file:

{php}include('jdf.php');{/php}

 

then i replace {$datecreated} by folowing line

{php}echo $shamsi = jdate("Y/m/d", strtotime($this->_tpl_vars["datecreated"]));{/php}

 

but i cant use this method at version 6

do you have any solution for this problem ?

 

download jdf.php link ---> jdf.scr.ir/download/dl.php

 

------------------------

code to convert Gregorian to Solar(Jalali)

include('jdf.php');

$Gregorian_date = "2016/01/16";

$Gregorian_date = strtotime($Gregorian_date);

$solar_date = jdate("Y/m/d", $Gregorian_date);

echo $solar_date;

------------------------

 

thank you

excuse me for my poor english

Link to comment
Share on other sites

i cant use {php} tag in .tpl file in version 6:

http://docs.whmcs.com/Version_6_Template_Migration_Guide#.7Bphp.7D_Block_Syntax

 

"An option was added to WHMCS 6 to enable use of the potentially dangerous {php} tag in custom templates. This option is disabled by default but can be enabled if required in Setup > General Settings > Security. We strongly encourage using hook functions over php code blocks inside of templates for backend interaction."

 

 

i dont want to enable php tag...

 

can i convert date without use of php tag in template?

Link to comment
Share on other sites

i cant use {php} tag in .tpl file in version 6:

you can - you just don't want to! :)

 

can i convert date without use of php tag in template?

if it were me, i'd carry on using your {php} solution - you know it works and how to use it, and it's no more "dangerous" in v6 than it was in v5... one day, you'll need an alternative solution, but not necessarily today.

 

there is a Smarty plugin that seems to work - though it comes with no instructions and i've no knowledge of farsi!

 

https://code.google.com/p/smartyjalaliplugin/downloads/list

 

if you upload all five files to /vendor/smarty/smarty/libs/plugins

 

you should then be able to edit the template to show jalali dates without the use of PHP...

 

today's date - {$smarty.now|date_format:"%d/%m/%Y"}
iranian date - {$smarty.now|jdate_format}
iranian date - {$smarty.now|jdate_format:"%Y/%m/%d"}

you will probably need to play with the output to get it right, using the date format options at...

 

http://php.net/manual/en/function.strftime.php

 

alternatively, you could post in Marketplace and pay someone to convert the PHP code to a hook.

 

but as I said previously, I would personally carry on using the {php} solution for now and try alternatives so that you are ready when {php} is disabled.

Link to comment
Share on other sites

  • 2 months later...

i write a plugin to change date without changing .tpl files

and it work...

but finding array data arrays is very difficult in this method.

add_hook('ClientAreaPageProductsServices', 1, function ($templateVariables)
{
/*foreach ($templateVariables as $Variables_name) {
	print_r($Variables_name);
}*/
$date  = $templateVariables['services']['0']['nextduedate'] ;
$date2 = jdate( 'Y/m/d', strtotime( $date ))  ;	

$replacements 	= $templateVariables['services']['0'];
$convetred = array( "nextduedate" => $date2);
$templateVariables['services']['0'] = array_replace($replacements, $convetred);
return($templateVariables);
} );

 

 

can some one help me to use folowing code to replace date ?

how can i use getChild('') to get date value

for example getChild('nextduedate')

use WHMCS\View\Menu\Item as MenuItem;
@add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   if (!is_null($primaryNavbar->getChild('Support'))) {
       $primaryNavbar->getChild('Support')
           ->addChild('sms_module', array(
               'label' => 'sms_notification',
               'uri' => 'index.php?m=sms_module',
               'order' => '100',
           ));
   }
});

Edited by mohammad50
add php tag
Link to comment
Share on other sites

i'm not sure I see what the navigation hook code has to do with your jalali hook... :?:

 

it'd probably be easier to query the database and regenerate the arrays again; manipulate the date format and send them back to Smarty - rather than trying to import the Smarty arrays in the hook..

 

btw - did you try the Smarty plugin? it works fine... :idea:

 

<td class="text-center"><span class="hidden">{$service.normalisedNextDueDate}</span>{$service.nextduedate}{if $service.nextduedate neq '-'} ... {$service.nextduedate|jdate_format:"%Y/%m/%d"}{/if}</td>

 

rZPOMz6.png

 

 

yes, you'll have to edit the templates to use it - but you were doing that with the previous {php} solution... anywhere there is a template, client or admin area, you can use the plugin. :)

Link to comment
Share on other sites

i want use getChild('') to get date array

for example getChild('nextduedate')

why?? getChild is used in navigation menus and sidebars hooks - it is NOT used to get Smarty arrays.

 

please dont offer me to edit .tpl files, because when i update whmcs, i must edit all .tpl files again for all my customer.

then post in Marketplace and pay someone to write it for you... seriously, a WHMCS developer who is familiar with hooks could write this quickly and save you a lot of time.

 

on Google, I can see a WHMCS addon that claims to do what you want - have you tried it?

 

http://shop.vbiran.ir/jalali-shamsi-date-whmcs-plugin/

Link to comment
Share on other sites

  • 4 years later...
  • 3 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated