<?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>La funzione "voucherInfo" richiama da remoto la funzione "CheckVoucher".</li>
</ol>
<pre><code class="language-php">function voucherInfo($username, $code){
    global $cfg;
    if($username){
        $xmws = new xmwsclient();
        
        $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'];
//    var_dump($res);
    }
}
</code></pre>
<ol start="2">
<li>La funzione "CheckVoucher" richiama in locale la funzione "getVoucher" che va ad estrapolare i dati dal db.</li>
</ol>
<pre><code class="language-php">    public function CheckVoucher(){
    
        $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>
<ol start="3">
<li>Qui lo script eseguito dalla funzione "CheckVoucher".</li>
</ol>
<pre><code class="language-php">    static function getVouchers(){
        global $zdbh;
        $currentuser = ctrl_users::GetUserDetail();
        $vouchers = $zdbh-&gt;prepare("SELECT * FROM ".self::$module_db.".x_vouchers 
                                        WHERE reseller_ac_id_fk=:user_id 
                                        AND voucher_deleted_ts IS NULL;");
        $vouchers-&gt;bindParam(':user_id', $currentuser['userid']);
        $vouchers-&gt;execute();
        $res = array();
        if (!fs_director::CheckForEmptyValue($vouchers)) {
            while ($row = $vouchers-&gt;fetch()) {
               $active_text = '&lt;span class="label label-danger"&gt;No&lt;/span&gt;';
               if($row['active_yn'] == 1){
                   $active_text = '&lt;span class="label label-success"&gt;Yes&lt;/span&gt;';
               }

               $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';
               }
               
/*               //usages
               $total_usages = 0;
            $sql = "SELECT COUNT(*) AS total_usages FROM ".self::$module_db.".x_invoices 
                        WHERE invoice_voucher_id=:id AND invoice_deleted_ts IS NULL";
            $numrows = $zdbh-&gt;prepare($sql);
            $numrows-&gt;bindParam(':id', $row['voucher_id']);
            if ($numrows-&gt;execute()) {
                $voucher_usages = $numrows-&gt;fetch();
                $total_usages = $voucher_usages['total_usages'];
            }
*/               
               
               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">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://dev.connect.gt/topic/222795/problema-importazione-dati-da-remoto-via-api</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 13:19:57 GMT</lastBuildDate><atom:link href="https://dev.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>