Example #1
0
function getOptimalCombinations($N, $M, $K)
{
    //Verifying for alpha numeric and special character values
    if (!is_numeric($N) || !is_numeric($M) || !is_numeric($K)) {
        return -1;
    } else {
        if (!isInteger($N) || !isInteger($M) || !isInteger($K)) {
            return -1;
        } else {
            //Verification for negetive values
            if ($N <= 0 || $M <= 0 || $K <= 0) {
                return -1;
            }
        }
    }
    //Checking for Invalid Conditions as mentioned in the problem statement
    if ($K > $M || $M > $N || $K > $N || $K > 50 || $M > 50 || $N > 65535) {
        return -1;
    }
    if ($K == $M) {
        return 1;
    }
    $noofWays = 0;
    //Core Logic Starts Here
    if (!(N % M)) {
        $noofSamples = $N / $M;
        $maxIterationLimit = gerCurPermutationValue($M, $K) - 1;
        $minIterationLimit = pow(2, $K - 1);
        $noofWays = 1;
        for ($i = $maxIterationLimit; $i >= $minIterationLimit; $i--) {
        }
    }
}
Example #2
0
function mustHaveArity($closure, $arity)
{
    $r = new \ReflectionObject(ofType('Closure', $closure));
    $m = $r->getMethod('__invoke');
    if (isInteger($arity) == $m->getNumberOfParameters()) {
        return $closure;
    }
    throwError("The closure doesnt has arity equals {$arity}");
}
Example #3
0
function baseType($value)
{
    if (isString($value)) {
        return 'string';
    }
    if (isInteger($value)) {
        return 'integer';
    }
    return 'object';
}
Example #4
0
function returnSum($inputAry)
{
    //Array which is to be partitioned
    $partitionAry = $inputAry;
    $partitionAryLen = count($partitionAry);
    //Verifying for alpha numeric and special character values
    for ($i = 0; $i < $partitionAryLen; $i++) {
        if (!is_numeric($partitionAry[$i])) {
            return "Invalid";
        } else {
            if (!isInteger($partitionAry[$i])) {
                return "Invalid";
            } else {
                if ($partitionAry[$i] > 65535) {
                    return "Invalid";
                }
            }
        }
    }
    $partitionArySum = array_sum($partitionAry);
    sort($partitionAry);
    //Veryfying for negetive array values
    if ($partitionAry[0] <= 0) {
        return "Invalid";
    }
    //Verifying for odd sum
    if ($partitionArySum % 2) {
        return "No";
    }
    $partitionVal = $partitionArySum / 2;
    //Verifying for a array index value exceeding half of the sum
    if ($partitionAry[$partitionAryLen - 1] > $partitionVal) {
        return "No";
    }
    //Core Logic
    $partitionTableAry[$partitionArySum];
    $partitionTableAry[0] = true;
    for ($k = 1; $k <= $partitionArySum; $k++) {
        $partitionTableAry[$k] = false;
    }
    for ($i = 0; $i < $partitionAryLen; $i++) {
        for ($j = $partitionArySum - $partitionAry[$i]; $j >= 0; $j--) {
            if ($partitionTableAry[$j]) {
                $partitionTableAry[$j + $partitionAry[$i]] = true;
            }
        }
    }
    if ($partitionTableAry[$partitionArySum / 2]) {
        return "Yes";
    } else {
        return "No";
    }
    error_reporting(E_ALL);
}
Example #5
0
 public function order_detail()
 {
     $this->load->helper('security');
     $order_id = xss_clean($this->input->get('id'));
     must_authenticated(site_url('tx/order_detail') . "?id=" . $order_id, USER_ROLE_USER);
     if ($order_id && isInteger($order_id)) {
         $this->load->model('tx_model');
         $this->load->model('voucher_model');
         $args['order'] = $this->tx_model->get_order($order_id);
         render('order/detail', $args, '');
         return;
     }
     redirect(base_url() . 'home', 'refresh');
 }
Example #6
0
function quicky_block_section($params, $content, $compiler)
{
    $block_name = 'section';
    $params = $compiler->_parse_params($params);
    if (!isset($params['name'])) {
        return $compiler->_syntax_error('Missing parameter \'name\' in section tag.');
    }
    if (!isset($params['loop'])) {
        return $compiler->_syntax_error('Missing parameter \'loop\' in section tag.');
    }
    $params['loop'] = $compiler->_dequote($params['loop']);
    if (!isset($params['start'])) {
        $params['start'] = '0';
    } else {
        $params['start'] = $compiler->_dequote($params['start']);
    }
    if (!isset($params['max'])) {
        $params['max'] = '-1';
    } else {
        $params['max'] = $compiler->_dequote($params['max']);
    }
    if (!isset($params['step'])) {
        $params['step'] = '1';
    } else {
        $params['step'] = $compiler->_dequote($params['step']);
    }
    $name = $compiler->_dequote($params['name']);
    $props = array('index', 'index_prev', 'index_next', 'iteration', 'first', 'last', 'rownum', 'loop', 'show', 'total');
    if (in_array($name, $props)) {
        return $compiler->_syntax_error('Disallowed value (\'' . $params['name'] . '\') of parameter \'name\' in section tag.');
    }
    $props[] = $name;
    $a = $compiler->block_props;
    $compiler->push_block_props($props, $block_name, $name);
    $block = $compiler->_tag_token($content, $block_name);
    $compiler->block_props = $a;
    $name = var_export($name, TRUE);
    $return = '<?php' . "\n" . '$section[' . $name . '] = array();' . "\n" . '$section[' . $name . '][\'s\'] = ' . (isInteger($params['loop']) ? $params['loop'] : 'isInteger(' . $params['loop'] . ')?' . $params['loop'] . ':sizeof(' . $params['loop'] . ')') . ';' . "\n" . '$section[' . $name . '][\'st\'] = ' . (isInteger($params['start']) ? $params['start'] : 'isInteger(' . $params['start'] . ')?' . $params['start'] . ':sizeof(' . $params['start'] . ')') . ';' . "\n" . '$section[' . $name . '][\'step\'] = ' . (isInteger($params['step']) ? $params['step'] : 'isInteger(' . $params['step'] . ')?' . $params['step'] . ':sizeof(' . $params['step'] . ')') . ';' . "\n" . 'if ($section[' . $name . '][\'s\'] > 0):' . ' for ($section[' . $name . '][\'i\'] = 0; $section[' . $name . '][\'i\'] < $section[' . $name . '][\'s\']-$section[' . $name . '][\'st\']' . ($params['max'] != '-1' ? ' and $section[' . $name . '][\'i\'] < ' . $params['max'] : '') . '; ++$section[' . $name . '][\'i\']): ' . '?>' . $block;
    if (($k = array_search('sectionelse', $compiler->_tag_stacks[$compiler->_tag_stack_n])) !== FALSE) {
        $return .= '<?php endif; ?>';
        unset($compiler->_tag_stacks[$compiler->_tag_stack_n][$k]);
    } else {
        $return .= '<?php endfor; endif; ?>';
    }
    return $return;
}
function returnHouseCondition($inputAry, $houseNumber)
{
    //Array which is to be partitioned
    $colonyInfoAry = $inputAry;
    $colonyInfoAryLen = count($colonyInfoAry);
    //Verifying for alpha numeric and special character values
    for ($i = 0; $i < $colonyInfoAryLen; $i++) {
        if (!is_numeric($colonyInfoAry[$i])) {
            return -1;
        } else {
            if (!isInteger($colonyInfoAry[$i])) {
                return -1;
            } else {
                //Verification for negetive values
                if ($colonyInfoAry[$i] < 0) {
                    return -1;
                }
            }
        }
    }
    //Checking for Invalid House Number
    if ($houseNumber > $colonyInfoAryLen || $houseNumber <= 0 || !is_numeric($houseNumber)) {
        return -1;
    }
    //First house aggregate value should not be 0
    //Verification of first house and last house values since they have only one neighbour so value should not be greater than 2
    if (!$colonyInfoAry[0] || !$colonyInfoAry[1] || $colonyInfoAry[0] > 2 || $colonyInfoAry[$colonyInfoAryLen - 1] > 2) {
        return -1;
    }
    //@TODO: Need to put another condition for first house value verification
    //Core Logic
    $houseCdnInfoAry[$colonyInfoAryLen];
    //Making first house condition to be 1 which indicates good
    $houseCdnInfoAry[0] = 1;
    for ($i = 1; $i < $colonyInfoAryLen; $i++) {
        if ($i > 1) {
            $secNeighbourValue = $houseCdnInfoAry[$i - 2];
        }
        $houseCdnInfoAry[$i] = $colonyInfoAry[$i - 1] - $houseCdnInfoAry[$i - 1] - $secNeighbourValue;
    }
    //print_r($houseCdnInfoAry);
    //error_reporting(E_ALL);
    return $houseCdnInfoAry[$houseNumber - 1];
}
function getBalanceInSatoshis($address)
{
    $client = new HttpClient();
    $response = $client->get(balanceLookupURL($address));
    if ($response->statusCode == 200 && isInteger($response->content)) {
        return intval($response->content);
    } else {
        $e = strtolower($response->content);
        preg_match('@<title>(.*)</title>@', $response->content, $matches);
        $title = at($matches, 1);
        if ($e == 'checksum does not validate' || beginsWith($e, 'illegal character') || in_array($e, array('input to short', 'input too short'))) {
            throw new InvalidAddress("{$address} appears to be an invalid Bitcoin address");
        } else {
            if (contains($e, 'cloudflare') && !empty($title)) {
                throw new NetworkError("CloudFlare-reported problem at blockchain.info: " . withoutPrefix($title, "blockchain.info | "));
            } else {
                if (contains(strtolower($title), 'under maintenance')) {
                    throw new NetworkError("Blockchain.info appears to be under maintenance");
                } else {
                    if (contains($e, "maximum concurrent requests reached")) {
                        throw new NetworkError("Maximum concurrent requests to Blockchain.info reached");
                    } else {
                        if (!empty($title)) {
                            throw new NetworkError("Unknown error when attempting to check address-balance " . "for ({$address}) via blockchain.info: {$title}");
                        } else {
                            if (trim($e) == '') {
                                throw new NetworkError("Blockchain.info returned empty/content-less response");
                            } else {
                                if ($e == 'lock wait timeout exceeded; try restarting transaction') {
                                    throw new NetworkError("Blockchain.info responded with error message about lock timeout");
                                } else {
                                    throw new \Exception("Unexpected result received from blockchain.info when " . "attempting to get balance of address {$address}: {$response->content}");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Example #9
0
/*** EFA Endpoint ***/
static $efa = 'http://bsvg.efa.de/bsvagstd/XML_DM_REQUEST?';
/*** Verify Method ***/
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
    header('Allow: GET');
    halt(405, 'error', 'Request method ' . $_SERVER['REQUEST_METHOD'] . ' is not supported');
}
/*** Verify Parameters ***/
if (!isset($_GET['city'])) {
    halt(400, 'error', 'Parameter missing: [city]');
}
if (!isset($_GET['stop'])) {
    halt(400, 'error', 'Parameter missing: [stop]');
}
if (isset($_GET['limit']) && !isInteger($_GET['limit'])) {
    halt(400, 'error', 'Parameter invalid: [limit] (must be integer)');
}
$city = $_GET['city'];
$stop = $_GET['stop'];
$limit = isset($_GET['limit']) ? $_GET['limit'] : 20;
/*** Find Stop ***/
$findStop_params = array('sessionID' => 0, 'locationServerActive' => 1, 'outputFormat' => 'json', 'type_dm' => 'stop', 'name_dm' => "{$city} {$stop}", 'limit' => $limit);
$findStop_url = $efa . http_build_query($findStop_params);
if (!($findStop_response = file_get_contents($findStop_url))) {
    halt(503, 'error', 'Problem communicating with EFA server');
}
$findStop_data = json_decode($findStop_response);
if (isset($findStop_data->dm->message)) {
    halt(404, 'error', 'No matching stop found');
}
Example #10
0
<?php

#require the check
require_once '../login_check.php';
# if is int get the user by his id otherwise we need the slug
if (isInteger($_GET['usersid'])) {
    $idFromSlug = $_GET['usersid'];
} else {
    $sSlug = $_GET['usersid'];
}
# load modals
$oUser = Singleton::getInstance('User');
$oFile = Singleton::getInstance('FileModel');
# get the users and assign them to the template
$oSmarty->assign('oUser', $oUser->getUsers($idFromSlug, $sSlug)[0]);
$oSmarty->assign('countFiles', $oFile->countFiles($idFromSlug = $oUser->getUserId()));
# active class
$oSmarty->assign('activeClass', 'users');
#display
$oSmarty->display('admin/profile/profile.tpl');
Example #11
0
function is_integerValue($value)
{
    return isInteger($value);
}
Example #12
0
 }
 /*
 if (file_exists("$SUBSPATH/$file[name]"))
 {
 	echo($lang_subtitles['std_file_already_exists']);
 	exit;
 }
 */
 //end process upload file
 //start process torrent ID
 if (!$_POST["torrent_id"]) {
     echo $lang_subtitles['std_missing_torrent_id'] . "{$file['name']}</b></font> !";
     exit;
 } else {
     $torrent_id = $_POST["torrent_id"];
     if (!is_numeric($_POST["torrent_id"]) || !isInteger($_POST["torrent_id"])) {
         echo $lang_subtitles['std_invalid_torrent_id'];
         exit;
     }
     $r = sql_query("SELECT * from torrents where id = " . sqlesc($torrent_id)) or sqlerr(__FILE__, __LINE__);
     if (!mysql_num_rows($r)) {
         echo $lang_subtitles['std_invalid_torrent_id'];
         exit;
     } else {
         $r_a = mysql_fetch_assoc($r);
         if ($r_a["owner"] != $CURUSER["id"] && get_user_class() < $uploadsub_class) {
             echo $lang_subtitles['std_no_permission_uploading_others'];
             exit;
         }
     }
 }
Example #13
0
<?php

$title = "View Comment";
include "header.php";
?>
  <p class="header">
  </p>

<?php 
if (!isset($_GET['id']) || !isInteger($_GET['id'])) {
    //header("Location: view.php?useSessionFilter=true");
    echo "<script>window.location = 'view.php?useSessionFilter=true'</script>";
    exit;
}
$id = $_GET['id'];
$data = db_query("SELECT * FROM LikeBack WHERE id={$id} LIMIT 1");
$comment = db_fetch_object($data);
if (!$comment) {
    //header("Location: view.php?useSessionFilter=true");
    echo "<script>window.location = 'view.php?useSessionFilter=true'</script>";
    exit;
}
?>
  <div class="subBar <?php 
echo $comment->type;
?>
">
   <a href="view.php?useSessionFilter=true"><img src="icons/gohome.png" width="32" height="32" alt=""></a> &nbsp; &nbsp;
   <strong><?php 
echo iconForType($comment->type) . " #{$comment->id}";
?>
Example #14
0
        }
        return $sum;
    }
    $input = explode(', ', $_POST['string']);
    ?>

<table>
    <tbody>

    <?php 
    foreach ($input as $str) {
        ?>
        <tr>
            <td> <?php 
        echo htmlentities(trim($str));
        ?>
</td>
            <td> <?php 
        echo isInteger($str) ? sumOfDigits($str) : "I cannot sum that";
        ?>
</td>
        </tr>
    <?php 
    }
    ?>

    </tbody>
</table>

<?php 
}
Example #15
0
    $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data)));
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    $oku = json_decode($result, true);
    $oku = $oku['success'];
    if (empty($name) || strlen($name) < 6) {
        $nameErr = true;
        $anyErr = true;
        $nameErrMsg = "İsminiz 6 haneden uzun olmalıdır lütfen tam isminizi kullanınız !";
    }
    if (empty($email) || !preg_match($emailPattern, $email)) {
        $emailErr = true;
        $anyErr = true;
        $emailErrMsg = "Lütfen kayıt için Agu mailinizi kullanınız !";
    }
    if (isInteger($depart)) {
        if (0 > $depart || $depart > 6) {
            $departErr = true;
            $anyErr = true;
            $departErrMsg = "Komik değil !";
        }
    } else {
        $departErr = true;
        $anyErr = true;
    }
    if ($oku != "1") {
        $anyErr = true;
        $captchaErr = true;
    }
}
function test_input($data)
Example #16
0
<?php

require_once './includes/template.php';
require_once './classes/pessoa.class.php';
require_once './classes/article.class.php';
function isInteger($input)
{
    return ctype_digit(strval($input));
}
/***********************************************************/
if (isset($_GET['id']) && !empty($_GET['id']) && isInteger($_GET['id'])) {
    $isOk = true;
    $id_artigo_get = $_GET['id'];
    $a = new Article();
    $artigo_dados = $a->getArticlebyID($id_artigo_get);
    $tags_dados = $a->getTagsbyID($id_artigo_get);
    if ($artigo_dados != 0 && $tags_dados != 0) {
        $id_artigo = $artigo_dados[0]['id_artigo'];
        $autor_artigo = $artigo_dados[0]['autor_artigo'];
        $nomeAutor = $artigo_dados[0]['nome'];
        $titulo_artigo = mb_strtoupper($artigo_dados[0]['titulo_artigo'], 'UTF-8');
        $data_artigo = $artigo_dados[0]['data_artigo'];
        $id_categoria = $artigo_dados[0]['id_categoria'];
        $nome_categoria = $artigo_dados[0]['nome_categoria'];
        $texto_artigo = $artigo_dados[0]['texto_artigo'];
        $data_revisao = $artigo_dados[0]['data_revisao'];
        $autor_revisao = $artigo_dados[0]['autor_revisao'];
        $numero_revisao = $artigo_dados[0]['numero_revisao'];
        $data_artigo = date('d/m/Y', strtotime($data_artigo));
        $tags = "";
        $first = true;
Example #17
0
    if ($seekat != 0) {
        fseek($fh, $seekat);
        print "FLV";
        print pack('C', 1);
        print pack('C', 1);
        print pack('N', 9);
        print pack('N', 9);
    }
    while (!feof($fh)) {
        print fread($fh, 10000);
    }
    fclose($fh);
}
function isInteger($x)
{
    return is_numeric($x) ? intval(0 + $x) == $x : false;
}
$b_secure = true;
$path = '/home/.../';
$a_movies[1] = $path . 'movie1.flv';
$a_movies[2] = $path . 'movie2.flv';
$a_movies[3] = $path . 'movie3.flv';
$vidID = $_GET["vidID"];
$vidPosition = $_GET["vidPosition"];
if ($b_secure) {
    // I decided to use a file ID instead of a file name to make the script more secure
    if (isInteger($vidID) && $vidID <= sizeof($a_movies)) {
        $s_file = $a_movies[$vidID];
        f_StreamFLV($s_file, $vidPosition);
    }
}
Example #18
0
function isIntegerInRange ($integer_string, $low, $high) {
/* range is inclusive, so includes high and low values*/

    if  (!isInteger($integer_string)) {

    return false;
    }

    $myinteger=intval($integer_string);
    if (($myinteger < $low) or ($myinteger > $high)) {
    return false;
    } else {
    return true;
    }
}
Example #19
0
require_once '../classes/Application.php';
require_once '../classes/incidents.php';
require_once '../classes/Calendrier.php';
$Impacte = new Impact();
if (!empty($_POST)) {
    $errors = array();
    $_POST['Incident_risqueAggravation'] = isset($_POST['Incident_risqueAggravation']) ? 1 : 0;
    $_POST['Incident_dejaApparu'] = isset($_POST['Incident_dejaApparu']) ? 1 : 0;
    $_POST['Incident_previsible'] = isset($_POST['Incident_previsible']) ? 1 : 0;
    /*
    Contrôle des champs obligatoire
    */
    if (empty($_POST['IdAppli'])) {
        $errors['IdAppli'] = "Vous devez remplir le champ Application!";
    }
    if (!isInteger($_POST['Incident_Impact_jourhommeperdu']) && !empty($_POST['Incident_Impact_jourhommeperdu'])) {
        $errors['Incident_Impact_jourhommeperdu'] = "Le champ jours homme perdu doit etre numérique  !";
    }
    if (empty($_POST['Incident_Impact_datedebut'])) {
        $errors['Incident_Impact_datedebut'] = "Vous devez remplir le champ début impact!";
    }
    if (!$_POST['Incident_Impact_impactmetier']) {
        $errors['Incident_Impact_impactmetier'] = "L'Impact métier n'est pas valide!";
    }
    if (empty($_POST['Incident_Impact_description'])) {
        $errors['Incident_Impact_description'] = "Vous devez remplir le champ Description de l'impact!";
    }
    if (empty($errors)) {
        // Impacte
        $impacte = new Impact();
        $impacte->setParam(NULL, $numincident, $_POST['IdAppli'], $_POST['Incident_Impact_datedebut'], $_POST['Incident_Impact_datefin'], $_POST['Incident_Impact_dureereelle'], $_POST['Incident_Impact_jourhommeperdu'], $_POST['Incident_Impact_impactmetier'], $_POST['Incident_Impact_impact'], $_POST['Incident_Impact_sla'], $_POST['Incident_Impact_criticite'], $_POST['Incident_Impact_description']);
Example #20
0
function fIsInteger()
{
    return function ($d) {
        return isInteger($d);
    };
}
Example #21
0
function updVSTRule()
{
    // this is used for making throwing an invalid argument exception easier.
    function updVSTRule_get_named_param($name, $haystack, &$last_used_name)
    {
        $last_used_name = $name;
        return isset($haystack[$name]) ? $haystack[$name] : NULL;
    }
    global $port_role_options, $sic;
    $taglist = genericAssertion('taglist', 'array0');
    assertUIntArg('mutex_rev', TRUE);
    $data = genericAssertion('template_json', 'json');
    $rule_no = 0;
    try {
        $last_field = '';
        foreach ($data as $rule) {
            $rule_no++;
            if (!isInteger(updVSTRule_get_named_param('rule_no', $rule, $last_field)) or !isPCRE(updVSTRule_get_named_param('port_pcre', $rule, $last_field)) or NULL === updVSTRule_get_named_param('port_role', $rule, $last_field) or !array_key_exists(updVSTRule_get_named_param('port_role', $rule, $last_field), $port_role_options) or NULL === updVSTRule_get_named_param('wrt_vlans', $rule, $last_field) or !preg_match('/^[ 0-9\\-,]*$/', updVSTRule_get_named_param('wrt_vlans', $rule, $last_field)) or NULL === updVSTRule_get_named_param('description', $rule, $last_field)) {
                throw new InvalidRequestArgException($last_field, $rule[$last_field], "rule #{$rule_no}");
            }
        }
        commitUpdateVSTRules($_REQUEST['vst_id'], $_REQUEST['mutex_rev'], $data);
    } catch (Exception $e) {
        // Every case that is soft-processed in process.php, will have the working copy available for a retry.
        if ($e instanceof InvalidRequestArgException or $e instanceof RTDatabaseError) {
            @session_start();
            $_SESSION['vst_edited'] = $data;
        }
        throw $e;
    }
    rebuildTagChainForEntity('vst', $_REQUEST['vst_id'], buildTagChainFromIds($taglist), TRUE);
    showFuncMessage(__FUNCTION__, 'OK');
}
Example #22
0
    <strong>Version:</strong>
    <select name="version">
     <option>(All)</option>
<?php 
if (isset($_GET['useSessionFilter']) && $_GET['useSessionFilter'] == "true") {
    $_POST = $_SESSION['postedFilter'];
}
$_SESSION['postedFilter'] = $_POST;
// Change the status of a comment:
$existingStatus = array("New" => true, "Confirmed" => true, "Progress" => true, "Solved" => true, "Invalid" => true);
if (isset($_GET['markAs']) && isset($existingStatus[$_GET['markAs']]) && isset($_GET['id'])) {
    $id = $_GET['id'];
    // Before, id was "comment_###":
    //$id = split("_", $_GET['id']);
    //$id = (isset($id[1]) ? $id[1] : "ERROR");
    if (isInteger($id)) {
        db_query("UPDATE LikeBack SET status='" . $_GET['markAs'] . "' WHERE id='{$id}'") or die(mysql_error());
        if (isset($_GET['isAJAX'])) {
            exit;
        }
        // The JavaScript will do the update. No reload wanted.
    }
}
// Figure out if we are filtering or if it is the first time:
$filtering = isset($_POST['filtering']);
$versionFilter = "";
$versions = db_query("SELECT version FROM LikeBack GROUP BY version ORDER BY date DESC") or die(mysql_error());
while ($line = db_fetch_object($versions)) {
    $version = htmlentities($line->version);
    // Only if the posted version is a valid version:
    $select = "";