<?php

function testUMC()
{
    print "pravilno se includa";
}

    /**
     * Function for storing variables into structure table!
     *
     * @param string $vars coma seprated, ie. q1=2,q2=6
     * @return unknown
     */
    function saveVarAutoFill($vars)
    {
        global $attrArray;
		global $errorReport;
		global $obj;

        include_once(PATH_TO_ROOT . "_support/phpsqlparser/PHPSQLParser.php");
        $sql = "SET " . $vars;

		try
		{
        	$parser = new PHPSQLParser($sql, true);
			foreach($parser->parsed['SET'] as $val)
	        {
	            if($val['expr_type'] == 'expression')
	            {
	                $q_name = $val['sub_tree'][0]['base_expr'];
	                $value = $val['sub_tree'][2]['base_expr'];
	                $attrArray[$q_name] = str_replace(array("'", "\""), array("", ""), $value);
	            }
	        }
		}
		catch(Exception $e)
		{
			$errorReport->addError($obj->q_name,"Error in saveVar function", array('original_message' => $e->getMessage()));
		}

    }

        /**
     * Function for fetching variables from structure table!
     *
     * @param string $vars comma seperated variables to be retrieved
     * @return unknown
     */
    function getVarAutoFill($vars)
    {
        global $attrArray;
		global $errorReport;
		global $obj;

        include_once(PATH_TO_ROOT . "_support/phpsqlparser/PHPSQLParser.php");
        $sql = "SELECT  " . $vars;
		try
		{
	        $parser = new PHPSQLParser($sql, true);
	        $rtnArray = array();
	        foreach($parser->parsed['SELECT'] as $val)
	           $rtnArray[$val['base_expr']] = $attrArray[strtolower($val['base_expr'])];

	        return $rtnArray;
		}
		catch(Exception $e)
		{
			$errorReport->addError($obj->q_name,"Error in getVar function", array('original_message' => $e->getMessage()));
		}
    }

    function sendSurveyToEmail($email, $id_group, $mailSet)
    {
        global $db;
        $sql = "INSERT IGNORE INTO " . DB_WARPIT_USERSPOOL . "._Interviewer SET email = '". $email ."'";
        $db->SQLexecute($sql);
        // duplicated email
        $sql = "SELECT id FROM ". DB_WARPIT_USERSPOOL ."._Interviewer WHERE email = '" . $email ."'";
        $res = $db->SQLexecute($sql);
        $zad = $db->fetchAssoc($res);
        $idInterviewer = $zad['id'];

        //id_group - grupo za maile ustvari na webuserspool in poglej stevilko v WarpitOnline_Webuserspool_groups

        $sql = "INSERT IGNORE INTO ". DB_WARPIT_USERSPOOL ."._group_link SET id_group = " . $id_group . ", id = ".$idInterviewer;
        $db->SQLexecute($sql);

        $sql = "INSERT IGNORE INTO " . DB_WARPIT_USERSPOOL . "._MailStatistic
              SET
                mail_set = $mailSet,
                interviewer_id = ".$idInterviewer.",
                mail_address = '" . $email . "',
                date_sent = NOW(),
                mail_status = 1 ";

        $db->SQLexecute($sql);


        $_POST['mailSet'] = $mailSet;
        $_POST['mailStatus'] = 1;

        $sessionHandling = 1;
        ob_start();
        include(PATH_TO_ROOT . "webuserspool/_ajax/ajax.sendMail.php");
        ob_end_clean();
    }
?>
