<?php

require_once dirname(__FILE__) . '/../../lib/phoneprovisioning.php';
require_once dirname(__FILE__) . '/../tiptel-30xx/Tiptel30xx.php';
require_once dirname(__FILE__) . '/../tiptel-30xx/provisioning.php';
require_once 'Htek.php';

class HtekPhoneProvisioning extends TiptelPhoneProvisioning
{

    const LOG_TAG = 'htek-dls';

    protected function checkMacAddress($mac)
    {
        return parent::checkMacAddress($mac);
    }

    protected function checkUserAgent($ua)
    {
        $ua_parts = explode(' ', $ua);

        if (strToLower(@$ua_parts[0]) === 'htek') {
            $found = false;
            $phoneType = substr(strToLower(@$ua_parts[1]), 0, 2);
            if ($phoneType === 'uc') {
                $ua_model = strToLower(@$ua_parts[0] . @$ua_parts[1]);
                if (endsWith($ua_model, '912')) {
                    $ua_model .= 'p';
                }
                foreach ($this->getSupportedPhoneModels() as $model) {
                    if ($model->getUserAgent() == $ua_model) {
                        $this->setCurrentPhoneModel($model);
                        $found = true;
                        break;
                    }
                }
            }
            # find out the firmware version of the phone
            $fw_vers = (preg_match('/(\d+\.\d+\.\d+\.\d+)/', @$ua_parts[2], $m)) ? $m[1] : '0.0.0.0';
            $fw_vers_nrml = $this->tiptel_normalize_version($fw_vers);
            $this->setCurrentFirmwareVersion($fw_vers_nrml);
            return $found;
        }
        return parent::checkUserAgent($ua);
    }

    protected function getSupportedPhoneModels()
    {
        return Htek::getSupportedPhoneModels();
    }

    protected function getFirmwareServerPath($Phone)
    {
        return "";
    }
}
