• User

    Problema importazione dati da remoto via API

    Ciao a tutti.
    Sto utilizzando il famoso pannello sentora che utilizza moduli nativi per zpanel.
    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.
    Cercherò di essere più chiaro possibile.

    Omettendo tutto il resto degli script focalizzo l'attenzione unicamente sulle funzioni incriminate cercando di descrivere tutto al meglio.

    1. La funzione "voucherInfo" richiama da remoto la funzione "CheckVoucher".
      [PHP]function voucherInfo($username, $code){
      global $cfg;
      if($username){
      $xmws = new xmwsclient();

       $xmws->InitRequest($cfg['panel_url'], 'xbilling', 'CheckVoucher', $cfg['api_key']);
       $xmws->SetRequestData('<zpx_user>' .$username. '</zpx_user>');
      
       $res = $xmws->XMLDataToArray($xmws->Request($xmws->BuildRequest()));
      
       if ($res['xmws']['response'] != '1101') {
           die("API Error: " . $res['xmws']['content']);
       }
      return $res['xmws']['content']['voucher'];
      

    // var_dump($res);
    }
    }
    [/PHP]
    2) La funzione "CheckVoucher" richiama in locale la funzione "getVoucher" che va ad estrapolare i dati dal db.
    [PHP]
    public function CheckVoucher(){

        $zpx_user = '';
        $request_data = ws_generic::XMLToArray($this->wsdata);
        if(isset($request_data['xmws']['content']['zpx_uid']) && 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 && $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' => $voucher_info['voucher_id'], 'code' => $voucher_info['voucher_code'], 'discount' => $voucher_info['discount'], 'type' => $discount_type);
                 $response_xml = $response_xml . ws_xmws::NewXMLContentSection('result', $voucher);
            }
    
            $dataobject = new runtime_dataobject();
            $dataobject->addItemValue('response', '');
            $dataobject->addItemValue('content', $response_xml);
    
            return $dataobject->getDataObject();
        }
    }
    
    public function GetPackageName(){
        $pkg_name = '';
        $pkg_id = 0;
        $request_data = ws_generic::XMLToArray($this->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->addItemValue('response', '');
            $dataobject->addItemValue('content', $response_xml);
    
            return $dataobject->getDataObject();
        }   
    }
    

    [/PHP]
    3) Qui lo script eseguito dalla funzione "CheckVoucher".
    [PHP]
    static function getVouchers(){
    global $zdbh;
    $currentuser = ctrl_users::GetUserDetail();
    $vouchers = $zdbh->prepare("SELECT * FROM ".self::$module_db.".x_vouchers
    WHERE reseller_ac_id_fk=:user_id
    AND voucher_deleted_ts IS NULL;");
    $vouchers->bindParam(':user_id', $currentuser['userid']);
    $vouchers->execute();
    $res = array();
    if (!fs_director::CheckForEmptyValue($vouchers)) {
    while ($row = $vouchers->fetch()) {
    $active_text = '<span class="label label-danger">No</span>';
    if($row['active_yn'] == 1){
    $active_text = '<span class="label label-success">Yes</span>';
    }

               $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->prepare($sql);
    $numrows->bindParam(':id', $row['voucher_id']);
    if ($numrows->execute()) {
    $voucher_usages = $numrows->fetch();
    $total_usages = $voucher_usages['total_usages'];
    }
    */

               array_push($res, array('code' => $row['voucher_code'],
                                      'discount' => $row['discount'],
                                      'type' => $row['voucher_code'],
                                      'active_text' => $active_text,
                                      'usage_type_text' => $usage_type,
                                      'discount_type_text' => $discount_type,
                                      'total_usages' => self::getVoucherUsages($row['voucher_id']),
                                      'id' => $row['voucher_id']));  
            }
            return $res;
        } else {
            return false;
        }            
    }  
    

    [/PHP]
    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.

    Spero che qualcuno riesca a darmi una mano.
    Saluti