Your IP : 216.73.217.6


Current Path : /home/smartconb/www/armencom33/acv2026/includes/
Upload File :
Current File : /home/smartconb/www/armencom33/acv2026/includes/function.inc.php

<?php
/**
 * User: zaven
 * Date: 04.06.2018
 * Time: 18:17
 * Project: cnpa_mail
 **/
if (!function_exists('_var_export')) {
    function _var_export($var, $return = false)
    {
        if ($return) {
            return var_export($var, true);
        } else {
            echo '<pre>' . var_export($var, true) . '</pre>' . "\n";
            return '';
            //exit;
        }
    }
}

function getData($table, $returnField, $indexField, $indexFieldValue, $extra = '')
{
    $returnValue = false;
    $sql = "SELECT " . $returnField . " FROM #__" . $table . " WHERE " . $indexField . " = '" . db_real_escape_string($indexFieldValue) . "' " . $extra;
    $result = db_query($sql);
    if ($result !== false && db_num_rows($result) > 0) {
        $returnValue = db_result($result, 0);
    }
    return $returnValue;
}

function getDataEx($sql, $returnField, $defaultValue = '')
{
    $returnValue = $defaultValue;
    //$sql = "SELECT " . $returnField . " FROM #__" . $table . " WHERE " . $indexField . " = '" . db_real_escape_string($indexFieldValue) . "'";
    $result = db_query($sql);
    if ($result !== false && db_num_rows($result) > 0) {
        $returnValue = array();
        while ($row = db_fetch_assoc($result)) {
            if (!is_array($returnField)) {
                if (db_num_rows($result) == 1) {
                    $returnValue = $row[$returnField];
                } else {
                    $returnValue[] = $row[$returnField];
                }
            } else {
                if (count($returnField) > 0) {
                    $returnValue[] = $row;
                }
            }
        }
        unset($row);
    }
    unset($result);
    return $returnValue;
}

function fixDateTimeForDB($tmpInitDateTime)
{
    $tmpDateArray = array();
    $tmpTimeArray = array();
    $tmpInitDateTimeArr = explode(' ', $tmpInitDateTime);
    $tmpInitDate = $tmpInitDateTimeArr[0];
    $tmpInitTime = $tmpInitDateTimeArr[1];

    $initDateArray = explode('/', $tmpInitDate);
    $formatArray = explode('/', 'd/m/y');

    for ($i = 0; $i < count($formatArray); $i++) {
        $formatArray[$i] = substr($formatArray[$i], 0, 1);
        $tmpDateArray[$formatArray[$i]] = $initDateArray[$i];
    }

    $initTimeArray = explode(':', $tmpInitTime);
    $formatArrayTime = explode(':', 'hh:mm:ss');

    for ($i = 0; $i < count($formatArrayTime); $i++) {
        $formatArrayTime[$i] = substr($formatArrayTime[$i], 0, 1);
        $tmpTimeArray[$formatArrayTime[$i]] = $initTimeArray[$i];
    }
    return $tmpDateArray['y'] . '-' . $tmpDateArray['m'] . '-' . $tmpDateArray['d'] . ' ' . $tmpTimeArray['h'] . ':' . $tmpTimeArray['m'] . ':' . $tmpTimeArray['s'];
}

function fixDateTimeFromDB($tmpInitDate, $dateTimeFormat = '')
{
    $tmpDate = '';
    //_var_export($tmpInitDate);
    if ($tmpInitDate != '') {
        $tmpInitDateTimeArray = explode(' ', $tmpInitDate);
        $tmpInitDateArray = explode('-', $tmpInitDateTimeArray[0]);
        $initDateArray['y'] = $tmpInitDateArray[0];
        $initDateArray['m'] = $tmpInitDateArray[1];
        $initDateArray['d'] = $tmpInitDateArray[2];
        if ($dateTimeFormat == "") {
            $formatArray = explode('/', 'd/m/y');
            for ($i = 0; $i < count($formatArray); $i++) {
                $formatArray[$i] = substr($formatArray[$i], 0, 1);
                $tmpDate .= $initDateArray[$formatArray[$i]] . '/';
                //$tmpDateArray[$formatArray[$i]] = $initDateArray[$i];
            }
            //return $tmpDate;
            $tmpReturn = substr($tmpDate, 0, -strlen('/'));
            if (count($tmpInitDateTimeArray) > 1)
                $tmpReturn .= ' ' . $tmpInitDateTimeArray[1];
            $tmpDate = $tmpReturn;
        } else {

            return date($dateTimeFormat, getDateTimeFromDB($tmpInitDate));
        }
    }
    return $tmpDate;
}

function getDateTimeFromDB($tmpInitDate)
{
    $tmpDate = '';
    //_var_export($tmpInitDate);
    if ($tmpInitDate != '') {
        $tmpInitDateTimeArray = explode(' ', $tmpInitDate);
        $tmpInitDateArray = explode('-', $tmpInitDateTimeArray[0]);
        $initDateArray['y'] = $tmpInitDateArray[0];
        $initDateArray['m'] = $tmpInitDateArray[1];
        $initDateArray['d'] = $tmpInitDateArray[2];

        $initDateArray['h'] = 0;
        $initDateArray['i'] = 0;
        $initDateArray['s'] = 0;
        if (count($tmpInitDateTimeArray) > 1) {
            $tmpInitTimeArray = explode(':', $tmpInitDateTimeArray[1]);
            $initDateArray['h'] = $tmpInitTimeArray[0];
            $initDateArray['i'] = $tmpInitTimeArray[1];
            $initDateArray['s'] = $tmpInitTimeArray[2];
        }
        return mktime($initDateArray['h'], $initDateArray['i'], $initDateArray['s'], $initDateArray['m'], $initDateArray['d'], $initDateArray['y']);
    }
    return $tmpDate;
}


function genereHash($id, $nom)
{
    return md5($id) . md5($nom) . md5($id . $nom . $id . $nom . $id . $nom);
}

if (!function_exists('generatePassword')) {
    function generatePassword($passwordCharMin = 5, $passwordCharMax = 8, $usePredefinedAlgorithm = true)
    {

        $res = "";
        if ($usePredefinedAlgorithm) {
            $res .= chr(rand(65, 90));
            $res .= chr(rand(97, 122));
            $res .= chr(rand(97, 122));
            $res .= rand(1000, 9999);
            $tmpCharCode = rand(1, 3);
            switch ($tmpCharCode) {
                case 2:
                    $res .= '-';
                    break;
                case 3:
                    $res .= '*';
                    break;
                default:
                    $res .= '+';
            }
            $res = str_replace('I', 'L', $res);
            $res = str_replace('O', 'T', $res);
            $res = str_replace('1', '8', $res);
            $res = str_replace('l', 'k', $res);
            $res = str_replace('I', 'B', $res);
        } else {
            $len = rand($passwordCharMin, $passwordCharMax);
            while (strlen($res) < $len) {
                $charCode = rand(48, 122);
                if ((($charCode >= 48) && ($charCode <= 57)) || (($charCode >= 64) && ($charCode <= 90)) || (($charCode >= 97) && ($charCode <= 122))) {
                    $res .= chr($charCode);
                }
            }
        }
        return $res;
    }
}

if (!function_exists('GenerateEmailLinkHash')) {
    function GenerateEmailLinkHash($tmpUserId, $timeVarName = 't', $userIdVarName = 'u', $hashVarName = 'h')
    {
        $returnArray = array();
        $nowDateTime = new DateTime();
        $returnArray[$timeVarName] = $nowDateTime->getTimestamp() + rand(0, 20) - rand(0, 20);
        $returnArray[$userIdVarName] = $tmpUserId;

        $timeHash = md5($returnArray[$timeVarName] . '');
        $tmpTimeUserHash = md5($returnArray[$timeVarName] . '_' . $tmpUserId);
        $tmpPos = rand(1, 31);
        $returnArray[$hashVarName] = substr($tmpTimeUserHash, 0, $tmpPos) . $timeHash . substr($tmpTimeUserHash, $tmpPos, strlen($tmpTimeUserHash) - $tmpPos);

        return $returnArray;
    }
}

if (!function_exists('GenerateEmailLinkHashJoined')) {
    function GenerateEmailLinkHashJoined($tmpUserId, $timeVarName = 't', $userIdVarName = 'u', $hashVarName = 'h')
    {
        $tmpArray = GenerateEmailLinkHash($tmpUserId, $timeVarName, $userIdVarName, $hashVarName);
        $returnArray = array();
        foreach ($tmpArray as $key => $val) {
            $returnArray[] = $key . '=' . $val;
        }
        unset($tmpArray);
        return implode('&', $returnArray);
    }
}

function directoryNamePrepare($string)
{
    $search = array("(", ")", "[", "]", "{", "}", "+", "\"", "`", "'", "ç", "æ", "œ", "á", "é", "í", "ó", "ú", "à", "è", "ì", "ò", "ù", "ä", "ë", "ï", "ö", "ü", "ÿ", "â", "ê", "î", "ô", "û", "å", "e", "i", "ø", "u", " ", "Ç", "Æ", "Œ", "Á", "É", "Í", "Ó", "Ú", "À", "È", "Ì", "Ò", "Ù", "Ä", "Ë", "Ï", "Ö", "Ü", "Ÿ", "Â", "Ê", "Î", "Ô", "Û", "Å", "E", "I", "Ø", "U");
    $replace = array("_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "c", "ae", "oe", "a", "e", "i", "o", "u", "a", "e", "i", "o", "u", "a", "e", "i", "o", "u", "y", "a", "e", "i", "o", "u", "a", "e", "i", "o", "u", "_", "C", "AE", "OE", "A", "E", "I", "O", "U", "A", "E", "I", "O", "U", "A", "E", "I", "O", "U", "Y", "A", "E", "I", "O", "U", "A", "E", "I", "O", "U");
    return str_replace($search, $replace, $string);
}

function getRandomTextOfType($table, $language_id, $type = 0, $scenarioId = 0, $scenarioFieldName = 'scenario_id')
{
    $returnVal = "";
    $sql = "SELECT COUNT(" . $table . "_id) as recordCount FROM #__" . $table . " WHERE language_id='" . db_real_escape_string($language_id) . "'";
    if ($type == 1) {
        $sql .= " AND " . $table . "_timestart>0";
    }
    $sql .= " AND " . $scenarioFieldName . " = '" . db_real_escape_string($scenarioId) . "'";
    $result = db_query($sql);
    if ($result !== false && db_num_rows($result) > 0) {
        $recordCount = db_result($result, 0);
        if ($recordCount > 0) {
            $sql = "SELECT " . $table . "_text, " . $table . "_timestart, " . $table . "_timeduration FROM #__" . $table . " WHERE language_id='" . db_real_escape_string($language_id) . "'";
            if ($type == 1) {
                $sql .= " AND " . $table . "_timestart>0";
            }
            $sql .= " AND " . $scenarioFieldName . " = '" . db_real_escape_string($scenarioId) . "'";
            $sql .= " LIMIT " . rand(0, $recordCount - 1) . ", 1";
            $result = db_query($sql);
            if ($result !== false && db_num_rows($result) > 0) {
                $result1 = db_fetch_assoc($result);
                if ($type == 0) {
                    $returnVal = $result1[$table . '_text'];
                } elseif ($type == 1) {
                    $returnVal = array(
                        'start' => $result1[$table . '_timestart'],
                        'duration' => $result1[$table . '_timeduration']

                    );
                }
            }
        }
    }

    return $returnVal;
}