Get the script which makes a call only if the user answers yes to the given question.

It is a function of the Jaxon\Request\Interfaces\Confirm interface.

@return string
550736
public function confirm($question, $yesScript, $noScript)
    {
        if(!$noScript)
        {
            return "jaxon.dialogs.overhang.confirm(" . $question . ",function(){" . $yesScript . ";})";
        }
        else
        {
            return "jaxon.dialogs.overhang.confirm(" . $question . ",function(){" . $yesScript . ";},function(){" . $noScript . ";})";
        }
    }
571315
private function _getScript()
    {
        $aVars = $this->getOptionVars();
        $sYesScript = 'jaxon.ajax.response.process(command.response)';
        $sNoScript = 'jaxon.confirm.skip(command);jaxon.ajax.response.process(command.response)';
        $sConfirmScript = jaxon()->dialog()->confirm('msg', $sYesScript, $sNoScript);
        $aVars['sConfirmScript'] = $this->render('jaxon::plugins/confirm.js', ['sConfirmScript' => $sConfirmScript]);

        return $this->render('jaxon::plugins/config.js', $aVars) . "\n" . $this->sJsReady . "\n";
    }
634020
public function getVerifyHandler()
    {
        if (is_callable($this->verifyHandler)) {
            return $this->verifyHandler;
        }

        return function ($password, $hash) {
            return password_verify($password, $hash);
        };
    }
554155
private function askPathToModify()
    {
        $names = $this->resolver->names();
        $count = count($names);

        $question = new Question('Enter # or name to modify or empty to continue');
        $question->setValidator(function ($value) use ($names, $count) {
            if ($value === null) {
                return $value;
            }

            if (!is_numeric($value) && array_search($value, $names) !== false) {
                return $value;
            } elseif ($value > 0 && $value <= $count) {
                return $names[$value - 1];
            }

            throw new \Exception("Please enter a name or a number between 1 and $count.");
        });
        $question->setAutocompleterValues($names);

        return $this->io->askQuestionThenRemove($question);
    }
30386
public function getHelp()
	{
		$help='Usage: '.$this->getCommandRunner()->getScriptName().' '.$this->getName();
		$options=$this->getOptionHelp();
		if(empty($options))
			return $help."\n";
		if(count($options)===1)
			return $help.' '.$options[0]."\n";
		$help.=" <action>\nActions:\n";
		foreach($options as $option)
			$help.='    '.$option."\n";
		return $help;
	}
138582
public function getScript()
    {
        $libraries = $this->getLibrariesInUse();
        $code = "jaxon.dialogs = {};\n";
        foreach($libraries as $library)
        {
            $code .= $library->getScript() . "\n";
        }
        return $code;
    }
1212808
public function isOK(){
        $boolReturn = false;
        
        if( ((!is_null($this->api_key))&&($this->api_key!="")) && ((!is_null($this->domaine))&&($this->domaine!="")) ){
            $boolReturn = true;
        }
        
        return $boolReturn;
    }
52628
public function getUsageMessage()
    {
        if (empty($this->scriptName)) {
            throw new GetoptException('Script name can not be empty');
        }
        $helpText = 'Usage: ' . $this->scriptName . ' '
            . $this->argumentsDescription . "\n\n" . 'Options:' ."\n"
        ;
        $args = array();
        $charCount = 0;
        foreach ($this->optionDefinitions as $option) {
            $arg = $this->getOptionString($option);
            $charCount = $charCount < strlen($arg) ? strlen($arg) : $charCount;
            $args[$arg] = $option->getDescription();
        }
        foreach ($args as $arg => $description) {
            $helpText .= str_pad($arg, $charCount + 1) . $description . "\n";
        }
        return $helpText;
    }
937457
public function getScript()
    {
        if(count($this->aScripts) == 0)
        {
            return '';
        }
        if(($this->sContext))
        {
            $js = "$('" . $this->sSelector . "', $('" . $this->sContext . "'))";
        }
        else
        {
            $js = "$('" . $this->sSelector . "')";
        }
        return $js . '.' . implode('.', $this->aScripts);
    }
779460
private function getJS()
    {

        if (strlen($this->JSrenderDocReady . $this->JSrender) == 0) {
            return "";
        }

        $js = "
                    <script type=\"text/javascript\">

                    ";
        if (strlen($this->JSrenderDocReady) > 0) {
            $js .= "   $(document).ready(function()
                        {
                        {$this->JSrenderDocReady}
                        } )
                      ";
        }
        $js .= $this->JSrender . "


                    </script>"
        ;

        return $js;
    }
430085
protected function execute()
    {
        $response = $this->service->IPGApiAction($this);

        if ($response instanceof Error) {
            return $response;
        }

        if ($this->function === self::FUNCTION_INSTALL) {
            return new Sell($response);
        }

        return new ConfirmRecurring($response);
    }
499929
public function getScript()
    {
        /*
         * JQuery variables sometimes depend on the context where they are used, eg. when their value depends on $(this).
         * When a confirmation question is added, the Jaxon calls are made in a different context,
         * making those variables invalid.
         * To avoid issues related to these context changes, the JQuery selectors values are first saved into
         * local variables, which are then used in Jaxon function calls.
         */
        $sVars = ''; // Javascript code defining all the variables values.
        $nVarId = 1; // Position of the variables, starting from 1.
        // This array will avoid declaring multiple variables with the same value.
        // The array key is the variable value, while the array value is the variable name.
        $aVariables = []; // Array of local variables.
        foreach($this->aParameters as &$xParameter)
        {
            $sParameterStr = $xParameter->getScript();
            if($xParameter instanceof \Jaxon\Response\Plugin\JQuery\Dom\Element)
            {
                if(!array_key_exists($sParameterStr, $aVariables))
                {
                    // The value is not yet defined. A new variable is created.
                    $sVarName = "jxnVar$nVarId";
                    $aVariables[$sParameterStr] = $sVarName;
                    $sVars .= "$sVarName=$xParameter;";
                    $nVarId++;
                }
                else
                {
                    // The value is already defined. The corresponding variable is assigned.
                    $sVarName = $aVariables[$sParameterStr];
                }
                $xParameter = new Parameter(Jaxon::JS_VALUE, $sVarName);
            }
        }

        $sPhrase = '';
        if(count($this->aMessageArgs) > 0)
        {
            $sPhrase = array_shift($this->aMessageArgs); // The first array entry is the question.
            // $sPhrase = "'" . addslashes($sPhrase) . "'"; // Wrap the phrase with single quotes
            if(count($this->aMessageArgs) > 0)
            {
                $nParamId = 1;
                foreach($this->aMessageArgs as &$xParameter)
                {
                    $sParameterStr = $xParameter->getScript();
                    if($xParameter instanceof \Jaxon\Response\Plugin\JQuery\Dom\Element)
                    {
                        if(!array_key_exists($sParameterStr, $aVariables))
                        {
                            // The value is not yet defined. A new variable is created.
                            $sVarName = "jxnVar$nVarId";
                            $aVariables[$sParameterStr] = $sVarName;
                            $sVars .= "$sVarName=$xParameter;";
                            $nVarId++;
                        }
                        else
                        {
                            // The value is already defined. The corresponding variable is assigned.
                            $sVarName = $aVariables[$sParameterStr];
                        }
                        $xParameter = new Parameter(Jaxon::JS_VALUE, $sVarName);
                    }
                    $xParameter = "'$nParamId':" . $xParameter->getScript();
                    $nParamId++;
                }
                $sPhrase .= '.supplant({' . implode(',', $this->aMessageArgs) . '})';
            }
        }

        $sScript = parent::getScript();
        $xDialog = jaxon()->dialog();
        if($this->sCondition == '__confirm__')
        {
            $sScript = $xDialog->confirm($sPhrase, $sScript, '');
        }
        elseif($this->sCondition !== null)
        {
            $sScript = 'if(' . $this->sCondition . '){' . $sScript . ';}';
            if(($sPhrase))
            {
                $xDialog->getAlert()->setReturn(true);
                $sScript .= 'else{' . $xDialog->warning($sPhrase) . ';}';
            }
        }
        return $sVars . $sScript;
    }
519302
public function prompt()
    {
        $this->writePrompt();

        $response = $this->valueOrDefault($this->getUserInput());

        if ($this->isValidResponse($response)) {
            return $response;
        }

        return $this->prompt();
    }
599492
public function confirm($question, $default = 'yes')
    {
        //Show required message
        echo "\n";
        echo "\t", $this->colorize($question." [$default] ", 'info'); echo " ";
        //Get user input
        $response = trim(fgets(STDIN));
        //Check if $response is yes or not
        if($response == 'yes' || $response == 'no')
        {
            //If is yes or not return the response
            return $response;
        }
        else if(empty($response))
        {
            //If response is empty return default value
            return $default;
        }
        else
        {
            //If not passed argument, repeat confirmation.
            $this->confirm($question, $default);
        }
    }
1074050
public function getScript() : ?string 
    {
        if ( ! $this->hasScript()) {
            $this->setScript($this->getDefaultScript());
        }
        return $this->script;
    }
449577
public function confirm(string $prompt, bool $yes = null): bool
    {
        $default = null;
        if ($yes === true) {
            $default = 'Y';
        } elseif ($yes === false) {
            $default = 'n';
        }

        return 'Y' === $this->ask($prompt, ['Y', 'n'], $default);
    }
653889
public function getConfirmCode()
    {
        $confirmCodeAttribute = $this->confirmCodeAttribute;
        return (is_string($confirmCodeAttribute) && !empty($confirmCodeAttribute)) ? $this->$confirmCodeAttribute : null;
    }