<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problema importazione dati da remoto via API]]></title><description><![CDATA[<p dir="auto">Ciao a tutti.<br />
Sto utilizzando il famoso pannello sentora che utilizza moduli nativi per zpanel.<br />
Il pannello e i moduli funzionano tutti alla perfezione ma ho un piccolo  problema con una funzione e sono sicuro che i più esperti sapranno  guidarmi per trovare la soluzione.<br />
Cercherò di essere più chiaro possibile.</p>
<p dir="auto">Omettendo tutto il resto degli script focalizzo l'attenzione unicamente  sulle funzioni incriminate cercando di descrivere tutto al meglio.</p>
<ol>
<li>
<p dir="auto">La funzione "voucherInfo" richiama da remoto la funzione "CheckVoucher".<br />
[PHP]function voucherInfo($username, $code){<br />
global $cfg;<br />
if($username){<br />
$xmws = new xmwsclient();</p>
<pre><code> $xmws-&gt;InitRequest($cfg['panel_url'], 'xbilling', 'CheckVoucher', $cfg['api_key']);
 $xmws-&gt;SetRequestData('&lt;zpx_user&gt;' .$username. '&lt;/zpx_user&gt;');

 $res = $xmws-&gt;XMLDataToArray($xmws-&gt;Request($xmws-&gt;BuildRequest()));

 if ($res['xmws']['response'] != '1101') {
     die("API Error: " . $res['xmws']['content']);
 }
return $res['xmws']['content']['voucher'];
</code></pre>
</li>
</ol>
<p dir="auto">//    var_dump($res);<br />
}<br />
}<br />
[/PHP]<br />
2) La funzione "CheckVoucher" richiama in locale la funzione "getVoucher" che va ad estrapolare i dati dal db.<br />
[PHP]<br />
public function CheckVoucher(){</p>
<pre><code>    $zpx_user = '';
    $request_data = ws_generic::XMLToArray($this-&gt;wsdata);
    if(isset($request_data['xmws']['content']['zpx_uid']) &amp;&amp; isset($request_data['xmws']['content']['voucher'])){
        $zpx_user = $request_data['xmws']['content']['zpx_uid'];
        $code = $request_data['xmws']['content']['voucher'];
    }
    
    //die(var_dump($request_data));
    

    if($zpx_user &amp;&amp; $code){
        $response_xml = "\n";
        $voucher_info = module_controller::getVoucher($zpx_user, $code);
        
        //die(var_dump($voucher_exists));
        
        if ($voucher_info){
                $discount_type = 'Once-Off';
        if($voucher_info['discount_type'] == 2){
            $discount_type = 'Recurring';
        }
            $voucher_check['voucher_exists'] = $voucher_exists;
             $voucher = array('id' =&gt; $voucher_info['voucher_id'], 'code' =&gt; $voucher_info['voucher_code'], 'discount' =&gt; $voucher_info['discount'], 'type' =&gt; $discount_type);
             $response_xml = $response_xml . ws_xmws::NewXMLContentSection('result', $voucher);
        }

        $dataobject = new runtime_dataobject();
        $dataobject-&gt;addItemValue('response', '');
        $dataobject-&gt;addItemValue('content', $response_xml);

        return $dataobject-&gt;getDataObject();
    }
}

public function GetPackageName(){
    $pkg_name = '';
    $pkg_id = 0;
    $request_data = ws_generic::XMLToArray($this-&gt;wsdata);
    if(isset($request_data['xmws']['content']['package_id'])){
        //$zpx_uid = $request_data['xmws']['content']['zpx_uid'];
        $pkg_id = $request_data['xmws']['content']['package_id'];
    }
    

    if($pkg_id){
        $response_xml = "\n";
        $pkg_name = module_controller::GetPackageName($pkg_id);
        
        if (!fs_director::CheckForEmptyValue($pkg_name)) {
            $package['name'] = $pkg_name;
             $response_xml = $response_xml . ws_xmws::NewXMLContentSection('package', $package);
        }

        $dataobject = new runtime_dataobject();
        $dataobject-&gt;addItemValue('response', '');
        $dataobject-&gt;addItemValue('content', $response_xml);

        return $dataobject-&gt;getDataObject();
    }   
}
</code></pre>
<p dir="auto">[/PHP]<br />
3) Qui lo script eseguito dalla funzione "CheckVoucher".<br />
[PHP]<br />
static function getVouchers(){<br />
global $zdbh;<br />
$currentuser = ctrl_users::GetUserDetail();<br />
$vouchers = $zdbh-&gt;prepare("SELECT * FROM ".self::$module_db.".x_vouchers<br />
WHERE reseller_ac_id_fk=:user_id<br />
AND voucher_deleted_ts IS NULL;");<br />
$vouchers-&gt;bindParam(':user_id', $currentuser['userid']);<br />
$vouchers-&gt;execute();<br />
$res = array();<br />
if (!fs_director::CheckForEmptyValue($vouchers)) {<br />
while ($row = $vouchers-&gt;fetch()) {<br />
$active_text = '&lt;span class="label label-danger"&gt;No&lt;/span&gt;';<br />
if($row['active_yn'] == 1){<br />
$active_text = '&lt;span class="label label-success"&gt;Yes&lt;/span&gt;';<br />
}</p>
<pre><code>           $usage_type = 'N/A';
           if($row['usage_type'] == 1){
               $usage_type = 'Once';
           } elseif($row['usage_type'] == 2){
               $usage_type = 'Multiple';
           }

           $discount_type = 'N/A';
           if($row['discount_type'] == 1){
               $discount_type = 'Once-Off';
           } elseif($row['discount_type'] == 2){
               $discount_type = 'Recurring';
           }
</code></pre>
<p dir="auto">/*               //usages<br />
$total_usages = 0;<br />
$sql = "SELECT COUNT(*) AS total_usages FROM ".self::$module_db.".x_invoices<br />
WHERE invoice_voucher_id=:id AND invoice_deleted_ts IS NULL";<br />
$numrows = $zdbh-&gt;prepare($sql);<br />
$numrows-&gt;bindParam(':id', $row['voucher_id']);<br />
if ($numrows-&gt;execute()) {<br />
$voucher_usages = $numrows-&gt;fetch();<br />
$total_usages = $voucher_usages['total_usages'];<br />
}<br />
*/</p>
<pre><code>           array_push($res, array('code' =&gt; $row['voucher_code'],
                                  'discount' =&gt; $row['discount'],
                                  'type' =&gt; $row['voucher_code'],
                                  'active_text' =&gt; $active_text,
                                  'usage_type_text' =&gt; $usage_type,
                                  'discount_type_text' =&gt; $discount_type,
                                  'total_usages' =&gt; self::getVoucherUsages($row['voucher_id']),
                                  'id' =&gt; $row['voucher_id']));  
        }
        return $res;
    } else {
        return false;
    }            
}  
</code></pre>
<p dir="auto">[/PHP]<br />
Dando per scontato che le funzioni di cui ai punti 2 e 3 funzionino a  dovere poiché preesistenti, il mio problema è che non riesco ad ottenere  i dati utilizzando lo script fatto da me al punto 1.</p>
<p dir="auto">Spero che qualcuno riesca a darmi una mano.<br />
Saluti</p>
]]></description><link>https://connect.gt/topic/222795/problema-importazione-dati-da-remoto-via-api</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Jul 2026 18:55:19 GMT</lastBuildDate><atom:link href="https://connect.gt/topic/222795.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 22 Apr 2016 01:37:08 GMT</pubDate><ttl>60</ttl></channel></rss>