account_id - ID аккаунта
tariff_link_id_find - ID тарифной связки которую необходимо изменить
tariff_current - ID нового ТП
Код: Выделить всё
<?xml version="1.0"?>
<urfa>
<!-- Zadaem glavnuy peremennye -->
<parameter name="account_id" value=""/>
<parameter name="tariff_link_id_find" value=""/>
<parameter name="tariff_current" value=""/>
<parameter name="return_type" value="integer_return"/>
<parameter name="debug" value="0"/>
<parameter name="nf" value="0"/>
<!-- Proverka na debug rejim -->
<if variable="debug" value="1" condition="eq">
<error code="100" comment="Debug Mode"/>
</if>
<!-- Poluchenie User ID -->
<call function="rpcf_get_user_by_account" output="0"/>
<!-- Proverka na nalichie starogo TP -->
<call function="rpcf_get_user_tariffs" output="0"/>
<for name="e" from="0" count="user_tariffs_size">
<set dst="tariff_link_id_tmp" src="tariff_link_id_array" src_index="e"/>
<if variable="tariff_link_id_tmp" value="tariff_link_id_find" condition="eq">
<set dst="nf" value="1"/>
</if>
</for>
<if variable="nf" value="0" condition="eq">
<error code="97" comment="Not found TP Link ID"/>
</if>
<!-- Poluchaem vse uslugi u polzovatela -->
<call function="rpcf_get_all_services_for_user" output="0"/>
<!-- Poluchaem dop info po uslugam u polzovatela -->
<for name="i" from="0" count="slink_id_count">
<set dst="service_type" src="service_type_array" src_index="i"/>
<set dst="slink_id" src="slink_id_array" src_index="i" />
<!-- For Periodic Service -->
<if variable="service_type" value="2" condition="eq">
<call function="rpcf_get_periodic_service_link" output="0"/>
<if variable="tariff_link_id" value="tariff_link_id_find" condition="eq">
<set dst="s" value="size(move_slink_id_array)"/>
<set dst="move_slink_id_array" dst_index="s,0" src="slink_id"/>
<set dst="move_slink_id_array" dst_index="s,1" src="service_type"/>
<set dst="move_slink_id_array" dst_index="s,2" src="discount_period_id"/>
<set dst="move_slink_id_array" dst_index="s,3" src="tariff_link_id"/>
<set dst="move_slink_id_array" dst_index="s,4" src="tariff_id"/>
<set dst="move_slink_id_array" dst_index="s,5" src="parent_id"/>
</if>
</if>
<!-- For IP Traffic Service -->
<if variable="service_type" value="3" condition="eq">
<call function="rpcf_get_iptraffic_service_link" output="0"/>
<if variable="tariff_link_id" value="tariff_link_id_find" condition="eq">
<set dst="s" value="size(move_slink_id_array)"/>
<set dst="move_slink_id_array" dst_index="s,0" src="slink_id"/>
<set dst="move_slink_id_array" dst_index="s,1" src="service_type"/>
<set dst="move_slink_id_array" dst_index="s,2" src="discount_period_id"/>
<set dst="move_slink_id_array" dst_index="s,3" src="tariff_link_id"/>
<set dst="move_slink_id_array" dst_index="s,4" src="tariff_id"/>
<set dst="move_slink_id_array" dst_index="s,5" src="parent_id"/>
<for name="x" from="0" count="ip_groups_count">
<set dst="ip_groups_array" dst_index="x,0" src="slink_id"/>
<set dst="ip_groups_array" dst_index="x,1" src="ip_address" src_index="x"/>
<set dst="ip_groups_array" dst_index="x,2" src="mask" src_index="x"/>
<set dst="ip_groups_array" dst_index="x,3" src="mac" src_index="x"/>
<set dst="ip_groups_array" dst_index="x,4" src="iptraffic_login" src_index="x"/>
<set dst="ip_groups_array" dst_index="x,5" src="iptraffic_password" src_index="x"/>
<set dst="ip_groups_array" dst_index="x,6" src="iptraffic_allowed_cid" src_index="x"/>
<set dst="ip_groups_array" dst_index="x,7" src="ip_not_vpn" src_index="x"/>
<set dst="ip_groups_array" dst_index="x,8" src="dont_use_fw" src_index="x"/>
<set dst="ip_groups_array" dst_index="x,9" src="router_id" src_index="x"/>
</for>
<for name="z" from="0" count="quotas_count">
<set dst="quotas_array" dst_index="z,0" src="slink_id"/>
<set dst="quotas_array" dst_index="z,1" src="tclass_id" src_index="z"/>
<set dst="quotas_array" dst_index="z,2" src="tclass_name" src_index="z"/>
<set dst="quotas_array" dst_index="z,3" src="quota" src_index="z"/>
</for>
</if>
</if>
<!-- For Telephone Service -->
<if variable="service_type" value="6" condition="eq">
<call function="rpcf_get_telephony_service_link" output="0"/>
<if variable="tariff_link_id" value="tariff_link_id_find" condition="eq">
<set dst="s" value="size(move_slink_id_array)"/>
<set dst="move_slink_id_array" dst_index="s,0" src="slink_id"/>
<set dst="move_slink_id_array" dst_index="s,1" src="service_type"/>
<set dst="move_slink_id_array" dst_index="s,2" src="discount_period_id"/>
<set dst="move_slink_id_array" dst_index="s,3" src="tariff_link_id"/>
<set dst="move_slink_id_array" dst_index="s,4" src="tariff_id"/>
<set dst="move_slink_id_array" dst_index="s,5" src="parent_id"/>
<for name="y" from="0" count="numbers_size">
<set dst="numbers_array" dst_index="y,0" src="slink_id"/>
<set dst="numbers_array" dst_index="y,1" src="item_id" src_index="y"/>
<set dst="numbers_array" dst_index="y,2" src="number" src_index="y"/>
<set dst="numbers_array" dst_index="y,3" src="login" src_index="y"/>
<set dst="numbers_array" dst_index="y,4" src="password" src_index="y"/>
<set dst="numbers_array" dst_index="y,5" src="allowed_cid" src_index="y"/>
</for>
</if>
</if>
</for>
<!-- Udaliaem tekushiy tariffniy plan -->
<set dst="tariff_link_id" src="tariff_link_id_find"/>
<call function="rpcf_unlink_user_tariff" output="0"/>
<!-- Chistim starie massivi -->
<remove name="ip_address"/>
<remove name="mask"/>
<remove name="mac"/>
<remove name="iptraffic_login"/>
<remove name="iptraffic_password"/>
<remove name="iptraffic_allowed_cid"/>
<remove name="ip_not_vpn"/>
<remove name="dont_use_fw"/>
<remove name="router_id"/>
<remove name="tclass_id"/>
<remove name="tclass_name"/>
<remove name="quota"/>
<remove name="item_id"/>
<remove name="number"/>
<remove name="login"/>
<remove name="password"/>
<remove name="allowed_cid"/>
<!-- Poluchaem info po novomu tarifu -->
<set dst="tariff_id" src="tariff_current"/>
<call function="rpcf_get_tariff" output="0"/>
<!-- Personaliziruem massiv -->
<for name="i" from="0" count="services_count">
<set dst="link_by_tp_default_array" dst_index="i" src="link_by_default_array" src_index="i"/>
<set dst="previous_slink_id_array" dst_index="i" value=""/>
</for>
<!-- Opredeliaem spisok uslug kotorie trebuetsia podkluchit -->
<for name="n" from="0" count="services_count">
<set dst="sid" src="service_id_array" src_index="n"/>
<set dst="service_type" src="service_type_array" src_index="n"/>
<if variable="service_type" value="2" condition="eq">
<call function="rpcf_get_periodic_service" output="0"/>
</if>
<if variable="service_type" value="3" condition="eq">
<call function="rpcf_get_iptraffic_service" output="0"/>
</if>
<if variable="service_type" value="6" condition="eq">
<call function="rpcf_get_telephony_service" output="0"/>
</if>
<for name="m" from="0" count="size(move_slink_id_array)">
<set dst="parent_id_old" src="move_slink_id_array" src_index="m,5"/>
<if variable="parent_id" value="parent_id_old" condition="eq">
<set dst="link_by_tp_default_array" dst_index="n" value="1" />
<set dst="previous_slink_id_array" dst_index="n" src="move_slink_id_array" src_index="m,0" />
</if>
</for>
</for>
<!-- Podkluchaem noviy tariffniy plan -->
<set dst="tariff_link_id" value="0"/>
<call function="rpcf_link_user_tariff" output="0"/>
<out var="tariff_link_id"/>
<!-- Podkluchaem uslugi v novom tariffnom plane -->
<for name="w" from="0" count="services_count">
<set dst="link_by_default" src="link_by_tp_default_array" src_index="w"/>
<set dst="previous_slink_id" src="previous_slink_id_array" src_index="w"/>
<set dst="service_id" src="service_id_array" src_index="w"/>
<set dst="service_type" src="service_type_array" src_index="w"/>
<set dst="unabon" value="1"/>
<set dst="unprepay" value="1"/>
<if variable="link_by_default" value="1" condition="eq">
<!-- Once service -->
<if variable="service_type" value="1" condition="eq">
<call function="rpcf_add_once_slink_ex" output="0"/>
</if>
<!-- Periodic service -->
<if variable="service_type" value="2" condition="eq">
<call function="rpcf_add_periodic_slink_ex" output="0"/>
</if>
<!-- IPTraffic service -->
<if variable="service_type" value="3" condition="eq">
<for name="j" from="0" count="size(ip_groups_array)">
<set dst="slink_id_tmp" src="ip_groups_array" src_index="j,0"/>
<if variable="previous_slink_id" value="slink_id_tmp" condition="eq">
<set dst="ip_address" dst_index="j" src="ip_groups_array" src_index="j,1"/>
<set dst="mask" dst_index="j" src="ip_groups_array" src_index="j,2"/>
<set dst="mac" dst_index="j" src="ip_groups_array" src_index="j,3"/>
<set dst="iptraffic_login" dst_index="j" src="ip_groups_array" src_index="j,4"/>
<set dst="iptraffic_password" dst_index="j" src="ip_groups_array" src_index="j,5"/>
<set dst="iptraffic_allowed_cid" dst_index="j" src="ip_groups_array" src_index="j,6"/>
<set dst="ip_not_vpn" dst_index="j" src="ip_groups_array" src_index="j,7"/>
<set dst="dont_use_fw" dst_index="j" src="ip_groups_array" src_index="j,8"/>
<set dst="router_id" dst_index="j" src="ip_groups_array" src_index="j,9"/>
</if>
</for>
<for name="k" from="0" count="size(quotas_array)">
<set dst="slink_id_tmp" src="quotas_array" src_index="k,0"/>
<if variable="previous_slink_id" value="slink_id_tmp" condition="eq">
<set dst="tclass_id" dst_index="k" src="quotas_array" src_index="k,1"/>
<set dst="tclass_name" dst_index="k" src="quotas_array" src_index="k,2"/>
<set dst="quota" dst_index="k" src="quotas_array" src_index="k,3"/>
</if>
</for>
<call function="rpcf_add_ip_slink_ex" output="0"/>
</if>
<!-- Telephone service -->
<if variable="service_type" value="6" condition="eq">
<for name="j" from="0" count="size(numbers_array)">
<set dst="slink_id_tmp" src="numbers_array" src_index="j,0"/>
<if variable="previous_slink_id" value="slink_id_tmp" condition="eq">
<set dst="item_id" dst_index="j" value="0"/>
<set dst="tel_number" dst_index="j" src="numbers_array" src_index="j,2"/>
<set dst="tel_login" dst_index="j" src="numbers_array" src_index="j,3"/>
<set dst="tel_password" dst_index="j" src="numbers_array" src_index="j,4"/>
<set dst="tel_allowed_cid" dst_index="j" src="numbers_array" src_index="j,5"/>
</if>
</for>
<call function="rpcf_add_tel_slink_ex" output="0"/>
</if>
</if>
</for>
</urfa>