array("start.php","novidades"), "about"=> array("footer.php?act=about","o-portal"), "terms"=> array("footer.php?act=terms","termos-condicoes"), "contact"=> array("contact.php?act=contact","contacto"), "article"=> array("start.php?act=item","artigo"), "bathroom"=> array("page.php?act=wc","casas-de-banho"), "kitchen"=> array("page.php?act=kitchen","cozinhas"), "livingroom"=> array("page.php?act=liv","sala-de-estar"), "bedroom"=> array("page.php?act=bed","quarto"), "balcony"=> array("page.php?act=balc","varandas"), "outside"=> array("page.php?act=out","exterior-jardins"), "smallspaces"=> array("page.php?act=small","espacos-pequenos"), "office"=> array("page.php?act=office","escritorio"), "store"=> array("page.php?act=store","loja"), "decoration"=> array("page.php?act=decor","decoracao"), "lighting"=> array("page.php?act=light","iluminacao"), "company"=> array("page.php?act=comp","empresas"), "archive"=> array("start.php?act=archive","arquivo"), "feeds"=>array("feeds.php","feeds"), ); ?>SYSTEM ERROR [$errno] $errstr: ". "Fatal error on line $errline in file $errfile
\n"; /* ", PHP " . PHP_VERSION . " (" . PHP_OS . ")
\n". "Aborting...
\n"; */ //exit(1); DisplayError($message); CloseDBConnection(); exit(1); break; case E_WARNING: //$message = "My WARNING [$errno] $errstr
\n"; $message = "SYSTEM WARNING [$errno] $errstr: ". "Warning on line $errline in file $errfile
\n"; DisplayError($message); break; /* case E_NOTICE: //$message = "My NOTICE [$errno] $errstr
\n"; $message = "My NOTICE [$errno] $errstr: ". "Notice on line $errline in file $errfile
\n"; DisplayError($message); break; */ /* default: //$message = "Unknown error type: [$errno] $errstr\n"; $message = "Unknown error type [$errno] $errstr: ". "Unknown error on line $errline in file $errfile
\n"; break; */ } /* Don't execute PHP internal error handler */ return true; } function UpdateClubsNumMembers(){ $SQL_query="UPDATE clubs SET num_members=0"; ExecuteSQLQuery($SQL_query); $SQL_query="UPDATE clubs c, (SELECT COUNT(*) as total_members, clubid FROM users GROUP BY clubid) AS memb ". " SET c.num_members=memb.total_members WHERE c.clubid=memb.clubid"; ExecuteSQLQuery($SQL_query); } function GetMonthNick($month){ global $_LANG_MONTH_NAME; return substr($_LANG_MONTH_NAME[intval($month)-1],0,3); } function GetMonthName($month){ global $_LANG_MONTH_NAME; return $_LANG_MONTH_NAME[intval($month)-1]; } function PlainText2HTML($text){ return str_replace(array("\r\n","\n","\r"),"
",$text); } function InsertGlobalInXML($root,$name,$value = null){ global $objSuper; if (!$root) $root = $objSuper; $node_globals = GetXMLGlobalsNode($root); $global = AddElementInXML($node_globals,$name,$value); return $global; } function GetXMLGlobalsNode2($root){ $objdom = $root->ownerDocument; $nodes_globals = $objdom->getElementsByTagname("globals"); $node_globals = $nodes_globals->item(0); if (!$node_globals) $node_globals= AddElementInXML($root,"globals"); //else $node_globals = $node_globals->item(0); return $node_globals; } function GetXMLGlobalsNode($root){ global $xmlGlobals,$objSuper; if (!$xmlGlobals) $xmlGlobals = AddElementInXML($objSuper,"globals"); //else $node_globals = $node_globals->item(0); return $xmlGlobals; } function GetXMLGlobalsNode3($root){ global $objSuper; $node_globals = $objSuper->children("globals"); if (!$node_globals) $node_globals= AddElementInXML($objSuper,"globals"); //else $node_globals = $node_globals->item(0); return $node_globals; } function GetDOMRoot2($objdom){ return $objdom->documentElement; } function GetDOMRoot($objdom){ global $objSuper; return $objSuper; //return $objdom->children("xml"); } function SetAttributeInXML2($objxml, $attribute, $value){ $objxml->setAttribute($attribute, $value); } function SetAttributeInXML($objxml, $attribute, $value){ if (!$objxml->attributes()->$attribute) $objxml->addAttribute($attribute, $value); } function TransformXML2HML($strXML, $xsl_file=null, $xsl_dir="xsl/"){ $file_basename = basename ($_SERVER["PHP_SELF"]); $xsl_local_dir = _ROOT_SITE_LOCAL . $xsl_dir; //Gets the full url and takes out the page being execute and replaces .php for .xsl if (!$xsl_file){ $strXSLFile= $xsl_local_dir. str_replace(".php",".xsl",$file_basename); if (!file_exists($strXSLFile) && _CURRENT_SCRIPT){ $strXSLFile = $xsl_local_dir.str_replace(".php",".xsl",_CURRENT_SCRIPT); } } else $strXSLFile = $xsl_local_dir.$xsl_file; if (stristr($_SERVER['OS'], "windows")) $path = dirname($_SERVER["PATH_TRANSLATED"]); else $path = dirname($_SERVER['SCRIPT_FILENAME']); $path = str_replace("\\\\", "/", $path); // Load the XML source //$xml = new DOMDocument('1.0', 'iso-8859-1'); $xml = new DOMDocument(); $xml->loadXML($strXML); //$xsl = new DOMDocument('1.0', 'iso-8859-1'); $xsl = new DOMDocument(); $xsl->load($strXSLFile); // Configure the transformer $proc = new XSLTProcessor; //$proc->setProfiling('profiling.txt'); $proc->importStyleSheet($xsl); // attach the xsl rules $html = $proc->transformToXML($xml); //create instance of xslt parser //$xh= XSLTProcessor(); //$arguments = array('/_xml' => $strXML); //xslt_set_base($xh, "file://".$path."/$xsl_dir"); //$html = xslt_process($xh, 'arg:/_xml', $strXSLFile , NULL, $arguments); $find = array(_LT,_GT,_SPACE,_AND); $replace = array("<",">"," ","&"); $out = str_replace($find, $replace,$html); //replaces output line 4 (title) with line 3 (after head) //$out_lines = split("\n",$out); //$aux = $out_lines[2]; //$out_lines[2]=$out_lines[3]; //$out_lines[3]=$aux; //return join("\n",$out_lines); return $out; } function AddElementInXML2($objroot,$tag,$value = null){ if (!$objroot->ownerDocument) DisplayError("ERROR: XML object does not existe. TAG is '$tag'. VALUE is '$value'"); else{ if ($value != null && !is_object($value)){ $replace = array(_LT,_GT,_SPACE,_AND,"'","\\n","\\"); $find = array("<",">"," ","&",_SINGLE_QUOTE,_NL,_BACKSLASH); $text = utf8_encode(str_replace($find, $replace,$value)); } $objdom = $objroot->ownerDocument; $objNew=$objdom->createElement($tag,$text); $new_node = $objroot->appendChild($objNew); return $new_node; } } function AddElementInXML($objroot,$tag,$value = null,$insert_if_null=true){ if (!is_object($objroot)) DisplayError("ERROR: XML object does not existe. TAG is '$tag'. VALUE is '$value'"); else{ if ($value != null && !is_object($value)){ $replace = array(_LT,_GT,_SPACE,_AND,"'","\\n","\\"); $find = array("<",">"," ","&",_SINGLE_QUOTE,_NL,_BACKSLASH); $text = utf8_encode(str_replace($find, $replace,$value)); $new_node = $objroot->addChild($tag,$text); }elseif($insert_if_null){ $new_node = $objroot->addChild($tag); } return $new_node; } } /* function CreateDOMXML($xsl_file=null){ $objDom = domxml_new_doc("1.0"); if ($xsl_file){ $pi = $objDom->create_processing_instruction("xml-stylesheet", 'type="text/xsl" href="'.$xsl_file.'"'); $objDom->append_child($pi); } $objSuper=$objDom->createElement("xml",null); $objDom->appendChild($objSuper); return array($objDom, $objSuper); } */ function CreateDOMXML2($xsl_file=null){ //$dom = new DOMDocument('1.0', 'iso-8859-1'); $dom = new DOMDocument(); if ($xsl_file){ $pi = $dom->create_processing_instruction("xml-stylesheet", 'type="text/xsl" href="'.$xsl_file.'"'); $dom->append_child($pi); } $element = $dom->createElement('xml'); // We insert the new element as root (child of the document) $dom->appendChild($element); return array($dom, $element); } function CreateDOMXML($xsl_file=null){ //$dom = new DOMDocument('1.0', 'iso-8859-1'); $dom = new SimpleXMLElement(''); //$element = $dom->addChild('xml'); //$element = $dom->children("xml"); //$element=$element[0]; // We insert the new element as root (child of the document) //$dom->appendChild($element); return array($dom, $dom); } function GetDOMXMLString2($objdom){ //return $objdom->dump_mem(true, 'UTF-8'); return $objdom->SaveXML(); } function GetDOMXMLString($objdom){ //return $objdom->dump_mem(true, 'UTF-8'); return @$objdom->asXML(); } function ValidateUser($userid,$pwd_md5,$username=null){ if ($userid){ $SQL_auth = "userid=$userid"; }elseif($username){ $SQL_auth = "username='$username'"; } if ($SQL_auth){ $SQL_query="SELECT userid,pwd_md5, level, var_value FROM users, system_vars WHERE $SQL_auth and pwd_md5='$pwd_md5' ". " AND var_name='"._SYSTEM_VAR_STATE."'"; $rs_users=ExecuteSQLQuery($SQL_query); $user_row=mysql_fetch_array($rs_users); $vpwd_md5=$user_row["pwd_md5"]; $level=intval($user_row["level"]); $userid = $user_row["userid"]; if ( intval($user_row["var_value"])==_SYSTEM_VAR_STATE_UP || $level==_SUPER){ if($pwd_md5==$vpwd_md5) return $userid; } } } function getremote(){ $ip = $_SERVER['REMOTE_ADDR']; if ($ip) $host = gethostbyaddr($ip); if (!$host) $host = $ip; return $host; } function AddXMLNumEntriesAdd($objxml){ $array = array(); for ($i=1; $i<=200; $i++){ $array[$i]=$i; } AddOptions2XML($objxml,number_new_fast_entries,$array); } function AddXMLDateTime($objxml,$long_date=false){ $xmlcombo_date = AddElementInXML($objxml,"combo_date"); AddXMLDate($xmlcombo_date,$long_date); for ($i=0; $i<=23; $i++){ AddXMLDateTimeUnit($xmlcombo_date,"hour",C2DigitStr(strval($i))); } for ($i=0; $i<=59; $i++){ AddXMLDateTimeUnit($xmlcombo_date,"minutes_seconds",C2DigitStr(strval($i))); } } function AddXMLDateTimeUnit($xml,$tag,$value,$text=null){ $xmlUnit = AddElementInXML($xml,$tag); if (!$text) $text = $value; AddElementInXML($xmlUnit,"value",$value); AddElementInXML($xmlUnit,"text",$text); } function AddXMLDateHour($objxml,$in_xml_globals=null){ if ($in_xml_globals) $objxml = GetXMLGlobalsNode($objxml); $xmlcombo_date = AddElementInXML($objxml,"combo_date"); AddXMLDate($xmlcombo_date); for ($i=1; $i<=24; $i++){ AddXMLDateTimeUnit($xmlcombo_date,"hour",C2DigitStr($i)); } return $xmlcombo_date; } function AddXMLDayMonth($objroot,$desc=null){ global $_LANG_MONTH_NAME; for ($i=1; $i<=31; $i=$i+1){ AddXMLDateTimeUnit($objroot,"day",C2DigitStr($i)); } for ($i=1; $i<=12; $i=$i+1){ if ($desc) $text = $_LANG_MONTH_NAME[$i-1]; else $text = C2DigitStr($i); AddXMLDateTimeUnit($objroot,"month",C2DigitStr($i),$text); } } function AddXMLDate($objxml,$long_date=false,$desc=null){ AddXMLDayMonth($objxml,$desc); $date = new _DateTime(); $date->SetDateTimeNow(); $year = $date->GetYear(); $year_max = $year+3; if ($long_date) $year_start = _LICENSE_YEAR_START_LONG; else $year_start = _LICENSE_YEAR_START; for ($year = $year_max; $year>=$year_start; $year--){ AddXMLDateTimeUnit($objxml,"year",$year); } } function AddXMLBirthDate($objxml){ $xmlcombo_bdate = AddElementInXML($objxml,"combo_bdate"); AddXMLDayMonth($xmlcombo_bdate); $date = new _DateTime(); $date->SetDateTimeNow(); $year = SelectYearFromDate($date); for ($I = $year; $I>1919; $I--) AddXMLDateTimeUnit($xmlcombo_bdate,"year",$I); } function OutputHML($strXML){ echo TransformXML2HML($strXML); } function OutputXML2HML($root,$xslt=null){ $time = floatval(microtime()); $xml = GetDOMXMLString($root,$xslt); $html = TransformXML2HML($xml); $time_dif =floatval(microtime())-$time; echo $html; if (_DEBUG_MODE=="on") echo "

XSLT time: $time_dif

"; } function LogXML($xml,$option=null){ if(_DEV_SITE=="on"){ $filename = "log/out.xml"; if ($option=="w"){ unlink($filename); } file_put_contents($filename,GetDOMXMLString($xml)); } } function SendMail($email,$strcc,$strMailFrom,$strSubject,$strBody, $strbcc = null,$htmlBody=null,$attachs=null){ LoadClass("htmlMimeMail5"); $mail = new htmlMimeMail5(); if (strstr(strtolower($_SERVER["OS"]), "windows")) $NL_OS = "\r\n"; else $NL_OS = "\n"; $strBody = str_replace ("\\\"", "\"", $strBody); $strBody = str_replace ("\\'", "'", $strBody); $strBody = str_replace ("#NL", $NL_OS, $strBody); if ($htmlBody){ $mail->setHtml($htmlBody); }else{ $mail->setText($strBody); } $mail->setFrom($strMailFrom); $mail->setSubject($strSubject); if ($strcc) $mail->setCc($strcc); if ($strbcc) $mail->setBcc($strbcc); if ($attachs){ foreach ($attachs as $attach){ //new FileAttachment('example.zip') //$mail->addAttachment($mail->getFile($attach[0]),$attach[1]); $mail->addAttachment(new FileAttachment($attach[0])); } } $result = $mail->send(array($email)); return $result; } function SendMail2($email,$strcc,$strMailFrom,$strSubject,$strBody, $strbcc = null,$htmlBody=null,$attachs=null){ LoadClass("Rmail"); $mail = new Rmail(); if (strstr(strtolower($_SERVER["OS"]), "windows")) $NL_OS = "\r\n"; else $NL_OS = "\n"; $NL_OS = "\r\n"; $strBody = str_replace ("\\\"", "\"", $strBody); $strBody = str_replace ("\\'", "'", $strBody); $htmlBody = str_replace ("#NL", "
", $strBody); $strBody = str_replace ("#NL", $NL_OS, $strBody); //if ($htmlBody){ $mail->setHtml($htmlBody); //}else{ $mail->setText($strBody); //} if (is_array($strMailFrom)){ list($emailfrom,$nameMailFrom) = $strMailFrom; $mail_auth = GetContactEmail($emailfrom); if ($emailfrom) $strMailFrom = CreateContactEmail($emailfrom,$nameMailFrom); if ($mail_auth && _SMTP_HOST){ $mail->setSMTPParams(_SMTP_HOST,null,null,null,$mail_auth[0],$mail_auth[1]); $sendtype = "smtp"; } } $mail->setFrom($strMailFrom); $mail->setSubject($strSubject); if ($strcc) $mail->setCc($strcc); if ($strbcc) $mail->setBcc($strbcc); if ($attachs){ foreach ($attachs as $attach){ //new FileAttachment('example.zip') //$mail->addAttachment($mail->getFile($attach[0]),$attach[1]); $mail->addAttachment(new FileAttachment($attach[0])); } } if (!$sendtype) $sendtype = "mail"; //$result = $mail->send(array($email),"smtp"); $result = $mail->send(array($email),$sendtype); return $result; } function MakeStrDate($day,$month,$year){ if ($day||$month||$year) return $day."-".$month."-".$year; } function MakeStrDateDB($day,$month,$year){ if ($day||$month||$year) return $year."-".C2DigitStr($month)."-".C2DigitStr($day); } function MakeStrMonthDay($month,$day){ return $month."-".$day; } function MakeStrTimeDB($seconds,$minutes,$hours){ if ($hours||$minutes||$seconds) return $hours.":".C2DigitStr($minutes).":".C2DigitStr($seconds); } function MakeStrDateTimeDB($seconds,$minutes,$hours,$day,$month,$year){ return MakeStrDateDB($day,$month,$year) . " ".MakeStrTimeDB($seconds,$minutes,$hours); } function EncodeEmail($email){ return str_replace(".", "[dot_image]", str_replace("@", "[at_image]",$email)); } function MakeStrHourDB($hour){ if (strlen($hour) < 3) return $hour.":00:00"; else return $hour; } function EncriptNumber($number){ $number=intval($number); $s=strftime("%S"); $s=$s+1; if ($s > 9) $str=$s; else $str="0".$s; $encript_numb=substr($str,0,1).$s*$number.substr($str,1,1); return $encript_numb; } function DecriptNumber($number){ $number=strval($number); if ($number){ $divisor=substr($number,0,1).substr($number,strlen($number)-1,1); $divisor=intval($divisor); $dividendo=substr($number,1,strlen($number)-2); $DecriptNumber=intval($dividendo)/$divisor; } else $DecriptNumber=0; return $DecriptNumber; } function C2DigitStr($k){ if ($k===null || $k==='' || float($k)===false || float($k)>9) return $k; elseif (float($k)<10){ return "0".float($k); } elseif($k===0) return "00"; } function ForcedC2DigitStr($k){ if (!intval($k)) return "00"; elseif(intval($k)>9) return $k; else return "0".intval($k); } function Autenticate($level_min, $via_org=null,$redirect=true){ global $via; if ( ($via==_PUBLIC && $level_min > $via) || ($via_org > _ENTRIES_STATE_AWAITING_CLUB && $via < _ADMIN)){ if ($redirect) Redirect2Login(); else return false; }elseif ($level_min != _PUBLIC) { $userid = $_SESSION['userid_session']; $pwd_md5 = $_SESSION['pwd_md5_session']; if ($level_min>$via){ if ($redirect) Redirect2RestictedAccess(_SYSTEM_DETAIL_PROCEED_LOGIN); else return false; } } return true; } function Redirect2RestictedAccess($detail=null){ global $SYSTEM_MESSAGE_RESTRICTED_ACCESS; header("Location: system_messages.php?message=$SYSTEM_MESSAGE_RESTRICTED_ACCESS&detail=$detail"); CloseDBConnection(); exit(); } function Redirect2Login($msg=null){ global $SYSTEM_MESSAGE_RESTRICTED_ACCESS; $vars = $_POST + $_GET; $get_url = ""; /* foreach ($vars as $var_name => $var_value){ $get_url .= "$var_name=".urlencode($var_value)."&"; } */ $file = basename($_SERVER["SCRIPT_NAME"]); if ($file=="login_ask.php" || $file=="login.php") $file = getVarPassed("nextscript",_TYPE_CHAR); if ($msg) $vars["message"]=$msg; $_SESSION["session_login_params"] = $vars; $_SESSION["session_login_script"] = $file; Redirect2("login_ask.php"); } function AutenticateLevel($level){ global $via; if (is_array($level)){ foreach ($level as $elem){ if ($elem == $via) return true; else { Redirect2RestictedAccess(); } } } else { if ($level > $via){ Redirect2RestictedAccess(); } } } function DebugInputValidation($str,$input,$inputx,$type){ if ($input!=$inputx){ $error = new SystemError("\n\nError in validation of INPUT!\nVAR:$str\nTYPE:$type\nVALUE:$input"); $error->LogDebug(); } return $inputx; } function getVarPassed($str,$type=null,$not_null=null,$max_size=null,$clear_delimiters=null,$vars=null,$trim=null){ global $_INPUT_FILTER, $_TYPES_INTEGER; if ($vars){ $var = $vars[$str]; }elseif (($var=$_POST[$str])==""){ $var=$_GET[$str]; } $var = $_INPUT_FILTER->FixStringDelimiters($var); $var = $_INPUT_FILTER->process($var); if($clear_delimiters) $var = ReplaceStringDelimiters($var); switch ($type) { case _TYPE_DAYS: case _TYPE_CHAR: case _TYPE_INTEGER: case _TYPE_EVENTID: /*$result = call_user_func_array("ValidateInput".$type,array(&$var,$not_null,$max_size,$str)); if(!$result){ $error = new SystemError("\n\nError in validation of INPUT!\nVAR:$str\nTYPE:$type\nVALUE:$var"); $error->LogDebug(); $var = ""; } */ $result = true; break; case _TYPE_EURO: case _TYPE_CLUB_EVENTID; case _TYPE_LANG: case _TYPE_COMPONENT: case _TYPE_FLOAT: case _TYPE_URL: case _TYPE_ENTRY_EXTRA_QUANTITY: case _TYPE_FEEDID: $result = call_user_func_array("ValidateInput".$type,array(&$var,$not_null,$max_size,$str)); break; case _TYPE_USERNAME: case _TYPE_NAME: case _TYPE_STRING: case _TYPE_PASSWORD: default: if (in_array($type,$_TYPES_INTEGER) && !ValidateInputInt($var,$not_null,$max_size)){ $var=""; //$error = new SystemError("\n\nError in validation of INPUT!\nVAR:$str\nTYPE:$type\nVALUE:$var"); //$error->LogDebug(); } $result = true; break; } if (!$result){ Redirect2RestictedAccess(); } else{ //2011-07-18 moved to the beggining //if($clear_delimiters) $var = ReplaceStringDelimiters($var); if($trim) $var = trim($var); if (!$var && $str=="action") $var = getVarPassed("act",_TYPE_ACTION); return $var; } } function ValidateInputDays(&$input,$not_null,$max_size){ return ValidateInputInt($input,$not_null,$max_size); } function ValidateInputEuro(&$input,$not_null,$max_size,$str){ if (!$input && !$not_null) return true; else { $input_aux = str_replace(array(",",";",":"),".",$input); if (is_numeric($input_aux)){ $input = FormatFee($input_aux); return true; } } return true; //return false; } function ValidateInputClubEventID(&$input,$not_null,$max_size,$str){ return ((!$input && !$not_null) || (is_numeric($input) && intval($input) > 0) || $input == _CLUB_EVENTS_ALL); } function ValidateInputUserLogin(&$input,$not_null,$max_size,$str){ //$input = str_replace (array("\"","'","\\","\r\n","\n"),"", $str); $allowed = "/[^a-z0-9\\_\\.\\-]/i"; //$allowed = "/^([A-Za-z0-9_\.-]){4,20}$/i"; $input = preg_replace($allowed,"",$input); //#CLEAN# //DebugInputValidation($str,$input,$inputx,"action"); return true; } function ValidateInputAction(&$input,$not_null,$max_size,$str){ //$input = str_replace (array("\"","'","\\","\r\n","\n"),"", $str); $allowed = "/[^a-z0-9\\040\\_\\+]/i"; $inputx = preg_replace($allowed,"",$input)."
"; //#CLEAN# //DebugInputValidation($str,$input,$inputx,"action"); return true; } function ValidateInputChr(&$input,$not_null,$max_size,$str){ //$input = str_replace (array("\"","'","\\","\r\n","\n"),"", $str); //#CLEAN# $input = str_replace (array("\"","'","\\","\r\n","\n"),"", $input); //$inputx = str_replace (array("\"","'","\\","\r\n","\n"),"", $input); //$input = DebugInputValidation($str,$input,$inputx,"chr"); return true; } /* function ValidateInputEntriesEventOrder(&$input,$not_null,$max_size){ global $_ORDER_BY_ENTRIES_EVENT; if ((!$input && !$not_null) || in_array($input,$_ORDER_BY_ENTRIES_EVENT)) return true; } */ function ValidateInputFeedID(&$input,$not_null,$max_size){ return ValidateInputInt($input,$not_null,$max_size); } function ValidateInputInt(&$input,$not_null,$max_size){ return ((!$input && !$not_null) || is_numeric($input)); } function ValidateInputFloat(&$input,$not_null,$max_size){ $input = str_replace(array(",",";",":"),".",$input); return ((!$input && !$not_null) || is_numeric($input)); } function ValidateInputURL(&$input,$not_null,$max_size){ if ($input && substr($input,0,4)!="http" && substr($input,0,3)!="ftp"){ $input = "http://".$input; } return true; } function ValidateInputLang(&$input,$not_null,$max_size){ global $LANGUAGES; if ((!$input && !$not_null) || in_array($input,$LANGUAGES)) return true; else require_once(LanguageFile(GetLanguage())); } function ValidateInputComponent(&$input,$not_null,$max_size){ global $COMPONENTS; $inputs = split(" ",$input); return ((!$input && !$not_null) || ElementsInArray($inputs,$COMPONENTS)); } function ValidateInputEventID(&$input,$not_null,$max_size){ return ((!$input && !$not_null) || (is_numeric($input) && intval($input) > 0) || $input == _CLUB_SYSTEM_EVENTID); } function ValidateInputEntryExtraQuantity(&$input,$not_null,$max_size){ if ($input && !is_numeric($input)){ $input = 1; } return ((!$input && !$not_null) || is_numeric($input)); } function ElementsInArray($elements, $array){ foreach ($elements as $element) { if(!in_array($element,$array)) return false; } return true; } function TestConnection($con_id=null){ global $_DB_SETTINGS; if (!$con_id){ $con_id = _DB_OASIS; } $openDB = $_DB_SETTINGS[$con_id][4]; if (!$openDB || gettype( $openDB ) == "unknown type" || !mysql_ping($openDB)){ $openDB = OpenDBConnection($con_id,true); } } function OpenDBConnection($con_id=null,$new_link=false){ global $_DB_SETTINGS; $DB_HOST ="localhost"; if (!$con_id){ $con_id = _DB_DEFAULT; } $DB_USERNAME = $_DB_SETTINGS[$con_id][_DB_SETTINGS_USER]; $DB_PASSWORD = $_DB_SETTINGS[$con_id][_DB_SETTINGS_PASS]; $DB_NAME = $_DB_SETTINGS[$con_id][_DB_SETTINGS_DB]; // $DB_HOST = $_DB_SETTINGS[$con_id][_DB_SETTINGS_HOST]; if($DB_USERNAME && $DB_PASSWORD && $DB_NAME && $DB_HOST){ $openDB=mysql_connect($DB_HOST,$DB_USERNAME,$DB_PASSWORD,$new_link); mysql_select_db($DB_NAME,$openDB); $_DB_SETTINGS[$con_id][_DB_SETTINGS_CONNECTION] = $openDB; return $_DB_SETTINGS[$con_id][_DB_SETTINGS_CONNECTION]; } } function CloseDBConnection($varDB=null){ global $DB; if ($varDB && mysql_ping($varDB)) mysql_close($varDB); elseif ($DB && mysql_ping($DB)) mysql_close($DB); } function GetFormatedStringDateNow(){ return date("Y-m-d H:i:s"); } function GetTimeParts($str_date=null,$date_format=null){ if($str_date==_DATE_TIME_NOW) $str_date = GetFormatedStringDateNow(); if ($date_format){ $format = str_replace("/","-",$date_format); list($format1,$format2,$format3) = explode("-",$format); } $str_date = str_replace("/","-",$str_date); preg_match_all("/(\S+)-(\S+)-(\S+)/",$str_date, $out, PREG_PATTERN_ORDER); $out =array_map("FirstElem",$out); list ($dummy, $Y, $m, $d) = $out; if ( (intval($Y) && $Y<1000) || ($format1=="d" && ($format3=="y" || $format3=="Y"))){ $aux = $Y; $Y=$d; $d=$aux; } if (strlen($Y)==2) $Y = _DateTime::ConvertShortYear2Long($Y); preg_match_all("/(\S+):(\S+):(\S+)/",$str_date, $out, PREG_PATTERN_ORDER); $out =array_map("FirstElem",$out); if (!$out[0]) { preg_match_all("/(\S+):(\S+)/",$str_date, $out, PREG_PATTERN_ORDER); $out =array_map("FirstElem",$out); } list($dummy, $H ,$i, $s) = $out; return array($Y, $m, $d, $H ,$i, $s); } function FirstElem($elem){ return $elem[0]; } function SecondElem($elem){ return $elem[1]; } // checks if the date in strdate1 is after the date in strdate2 function IsTimeAfter($strdate1, $strdate2){ if( strtotime($strdate1) > strtotime($strdate2) ) return true; else return false; } function IsTimeBetween($date,$sdate,$edate){ return ($sdate && $sdate && $edate && strtotime($date) >= strtotime($sdate) && strtotime($date) <= strtotime($edate)); } function AddXMLTelephonesTypes($objxml){ global $TELEPHONES_TYPES, $TELEPHONES_TYPES_DESCRIPTION; foreach ($TELEPHONES_TYPES as $type) { $xmltel_type = InsertGlobalInXML($objxml, "telephone_type"); AddElementInXML($xmltel_type, "name", $TELEPHONES_TYPES_DESCRIPTION[$type]); AddElementInXML($xmltel_type, "type", $type); } } function LoadClass($class,$comp=null){ require_once($comp."classes/" . $class .".php"); } function LoadRankingClass($class){ LoadClass("rankings/$class"); } function LoadCompClass($class,$comp=null){ global $comp_dir; if ($comp) $comp_dir = _COMPONETS_DIR.$comp; if ($comp_dir) LoadClass($class,$comp_dir."/"); } function LoadCompGlobals($comp=null){ global $comp_dir; if ($comp) $comp_dir = _COMPONETS_DIR.$comp."/"; if ($comp_dir) require($comp_dir."globals.php"); } function ExecuteSQLQuery($SQL_query,$myDB=null,$test_conn=null){ global $_DB_SETTINGS; if (!$myDB){ $myDB = _DB_DEFAULT; } if ($test_conn){ TestConnection($myDB); } if ($_DB_SETTINGS[$myDB] && !$_DB_SETTINGS[$myDB][_DB_SETTINGS_CONNECTION]){ OpenDBConnection($myDB); } if ($_DB_SETTINGS[$myDB][_DB_SETTINGS_CONNECTION]){ //PrintTimeNow($SQL_query); $time = microtime_float(); $result = mysql_query($SQL_query,$_DB_SETTINGS[$myDB][_DB_SETTINGS_CONNECTION]); $_DB_SETTINGS[$myDB][_DB_SETTINGS_TOTAL_QUERIES]++; $end_time =microtime_float(); $time_dif =$end_time-$time; $_DB_SETTINGS[$myDB][_DB_SETTINGS_TOTAL_TIME]=$time_dif + $_DB_SETTINGS[$myDB][_DB_SETTINGS_TOTAL_TIME]; //PrintTimeNow($SQL_query); if (!$_DB_SETTINGS[$myDB][_DB_SETTINGS_QUERIES]) $_DB_SETTINGS[$myDB][_DB_SETTINGS_QUERIES] = array(); array_push($_DB_SETTINGS[$myDB][_DB_SETTINGS_QUERIES],array($SQL_query,$time_dif)); } else{ DisplayError("
Empty SQL resource when trying to execute $SQL_query.
"); TestConnection($myDB); return; } if (!$result){ DisplayError("
The following query was not executed correctly:
$SQL_query
". "Error: ".mysql_errno().", ".mysql_error()."
"); TestConnection($myDB); } return $result; } function FormatTrueHour($hour){ switch ($hour){ case 24: return "23:59:59"; case 0: return "23:59:59"; default: return $hour; } } function FormatFakedHour($hour){ if ($hour == "23:59:59") return 24; else{ list($hour) = sscanf($hour, "%d:"); return $hour; } } function ExistsClub($name, $nick){ $SQL_query="SELECT * FROM clubs WHERE (nick='$nick' OR name='$name')"; $RecSet_query=ExecuteSQLQuery($SQL_query); $RecSet=mysql_fetch_array($RecSet_query); if ($RecSet) return true; else return false; } function GetCountryName($code,$nick=null){ global $_LANG_COUNTRIES, $_LANG_COUNTRIES_EXTRA; if (!$code || $code==_NO_COUNTRY){ return _LANG_NO_COUNTRY; } if (strlen($code)>2){ global $country_codes_a2_a3, $country_codes_a3_a2_sport; if (!$country_codes_a3_a2_sport){ $country_codes_a3_a2_sport = array_map("FirstElem",$country_codes_a2_a3); $country_codes_a3_a2_sport = array_flip($country_codes_a3_a2_sport); } $code = $country_codes_a3_a2_sport[$code]; } $all_lang_countries = array_merge($_LANG_COUNTRIES_EXTRA,$_LANG_COUNTRIES); $country_lang = $all_lang_countries[$code]; if (is_array($country_lang)){ if ($nick) $country_lang = $country_lang[1]; else $country_lang = $country_lang[0]; } return $country_lang; } function Countries2XMLA2A3($xml){ global $country_codes_a2_a3; foreach ( $country_codes_a2_a3 as $a2=>$a3){ $xmlA2A3 = AddElementInXML($xml,"country_a2_a3"); AddElementInXML($xmlA2A3,"a2",$a2); AddElementInXML($xmlA2A3,"a3",$a3[0]); } } function GetCountryCodeA3($code){ global $country_codes_a2_a3, $country_codes_a2_correction; if (strlen($code)>=3) return $code; if ($country_codes_a2_correction[$code]) $code = $country_codes_a2_correction[$code]; return $country_codes_a2_a3[$code][0]; } function GetCountryCodeA2($code,$sport=true){ global $country_codes_a2_a3, $country_codes_a3_a2, $country_codes_a3_a2_sport; if (strlen($code)<=2) return $code; if ($sport){ if (!$country_codes_a3_a2_sport){ $country_codes_a3_a2_sport = array_map("FirstElem",$country_codes_a2_a3); $country_codes_a3_a2_sport = array_flip($country_codes_a3_a2_sport); } return $country_codes_a3_a2_sport[$code]; }else{ if (!$country_codes_a3_a2){ $country_codes_a3_a2 = array_map("SecondElem",$country_codes_a2_a3); $country_codes_a3_a2 = array_flip($country_codes_a3_a2); } return $country_codes_a3_a2[$code]; } } function ExistsCountry($code){ return GetCountryCodeA3($code); } function GetRegionName($ccode, $rcode){ global $_LANG_COUNTRY_REGIONS; return $_LANG_COUNTRY_REGIONS[$ccode][$rcode]; } //function GetLanguage(){ // // /* Retrieves language from the following places // 1. Session // 2. Cookie // 3. Browser settings // 4. Country IP // 5. Default language // */ // // $lang = $_SESSION['language']; // // if (!$lang){ // $lang = $_COOKIE["oasis_language"]; // // if (!$lang){ // // $ip = $_SERVER["REMOTE_ADDR"]; // if ($ip==_LOCALHOST_IP) $lang = "pt_PT"; // // list ($country,$country_code ,$dummies) = GetGeoInfoFromIP($ip); // // if ($country_code){ // $langs = array(strtolower(GetCountryCodeA2($country_code,false))); // } // // //check first to see if they've been nice and // //set the language // elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { // //grab all the languages // $langs=explode(",",$_SERVER["HTTP_ACCEPT_LANGUAGE"]); // // $langs = array_map(create_function('$elem','return substr(strtolower($elem),0,2);'),$langs); // //select only the first two letters // //$choice=substr($value,0,2);) // } // //start going through each one // if ($langs){ // foreach ($langs as $value) { // // switch ($value) { // case "pt": // case "br": // case "ao": // case "mz": // case "gw": // case "cv": // case "mo": // $lang = "pt_PT"; // break; // /* // case "en": // $lang = "en_UK"; // break; // */ // default: // $lang = "en_UK"; // break; // //$lang = _LANGUAGE_DEFAULT; // } // } // } // if (!$lang && defined(_LANGUAGE_DEFAULT)){ // $lang = _LANGUAGE_DEFAULT; // }else{ // $lang = "en_UK"; // } // // setcookie("oasis_language",$lang); // } // } // return $lang; //} function GetLanguage(){ return _LANGUAGE_DEFAULT; } function LanguageFile($language){ return "languages/" . $language .".php"; } function AddXMLEventApproved($objxml){ global $EVENT_APPROVED; foreach($EVENT_APPROVED as $id => $text){ $xmlEA = InsertGlobalInXML($objxml,"event_approved"); AddElementInXML($xmlEA,"approvedid", $id); AddElementInXML($xmlEA,"text", $text); } } function AddXMLCountries($objxml, $list=null,$prefix=null,$nick=null){ $xmlCountries = AddElementInXML($objxml,$prefix."countries"); if (is_array($list) && count($list)){ foreach($list as $code){ AddXMLCountry($xmlCountries,$code,GetCountryName($code,$nick)); } }else{ global $_LANG_COUNTRIES; foreach ($_LANG_COUNTRIES as $code=>$country){ AddXMLCountry($xmlCountries,$code,GetCountryName($code,$nick)); } } } function AddXMLCountry($xmlCountries,$code,$country){ global $_LANG_COUNTRY_REGIONS; $xmlContry = AddElementInXML($xmlCountries,"country"); AddElementInXML($xmlContry,"code", $code); AddElementInXML($xmlContry,"code_a3", GetCountryCodeA3($code)); AddElementInXML($xmlContry,"name", $country); $country_regions = $_LANG_COUNTRY_REGIONS[$code]; if ($country_regions){ $xmlRegions = AddElementInXML($xmlContry,"regions"); foreach ($country_regions as $rcode=>$rname){ $xmlRegion = AddElementInXML($xmlRegions,"region"); AddElementInXML($xmlRegion,"code", $rcode); AddElementInXML($xmlRegion,"name", $rname); } } } function AddXMLSexTypes($objxml){ global $SEX_TYPES; foreach ($SEX_TYPES as $key=>$sex){ $xmlSex = AddElementInXML($objxml,"sex_type"); AddElementInXML($xmlSex,"id", $key); AddElementInXML($xmlSex,"text", $SEX_TYPES[$key]); AddElementInXML($xmlSex,"short_text", substr($SEX_TYPES[$key],0,1)); } } function AddXMLCalendarTypes($objxml){ global $CALENDAR_TYPES; $xmlSexTypes = AddElementInXML($objxml,"calendar_types"); while (list($c,$str_lng) = each($CALENDAR_TYPES)) { $xmlSex = AddElementInXML($xmlSexTypes,"calendar_type"); AddElementInXML($xmlSex,"typeid", $c); AddElementInXML($xmlSex,"text", $str_lng); } } function AddXMLClassTypes($objxml){ global $CLASS_TYPES, $CLASS_FEES; $xmlSexTypes = InsertGlobalInXML($objxml,"class_types"); while (list($c,$str_lng) = each($CLASS_TYPES)) { $xmlSex = AddElementInXML($xmlSexTypes,"class_type"); AddElementInXML($xmlSex,"typeid", $c); AddElementInXML($xmlSex,"text", $str_lng); $array_fees = $CLASS_FEES[$c]; if($array_fees) while (list(,$fee) = each($array_fees)) { AddElementInXML($xmlSex,"fee", $fee); } } } function AddXMLEventDisciplins($objxml){ global $EVENT_DISCIPLIN_DESC; $xmlSexTypes = AddElementInXML($objxml,"event_disciplins"); while (list($c,$str_lng) = each($EVENT_DISCIPLIN_DESC)) { $xmlSex = AddElementInXML($xmlSexTypes,"event_disciplin"); AddElementInXML($xmlSex,"disciplinid", $c); AddElementInXML($xmlSex,"text", $str_lng); } } function AddXMLEventQuantities($objxml){ global $EVENT_QUANTITIES; $xmlSexTypes = AddElementInXML($objxml,"event_quantities"); foreach ($EVENT_QUANTITIES as $quantity){ AddElementInXML($xmlSexTypes,"event_quantity", $quantity); } } function ResponsableObjInfo2XML($xml, $obj){ if ($obj->responsable_id && $obj->responsable_type){ $xmlResp = AddElementInXML($xml,"responsable_obj"); if ($obj->responsable_type == _NORMAL){ $xmlUserResp = AddElementInXML($xmlResp,"user"); $obj->responsable_obj->MainInfo2XML($xmlUserResp); if($obj->responsable_obj->club){ $xmlClub = AddElementInXML($xmlResp,"club"); $obj->responsable_obj->ClubInfo2XML($xmlClub); } } if ($obj->responsable_type == _ADMIN){ $xmlClub = AddElementInXML($xmlResp,"club"); $obj->responsable_obj->MainInfo2XML($xmlClub); } if ($obj->responsable_type == _SUPER){ $xmlSys = AddElementInXML($xmlResp,"system"); $obj->responsable_obj->MainInfo2XML($xmlSys); } } } function SetArray(&$a){ if (!$a) $a = array(); } function ResetArray($a){ SetArray($a); reset($a); } function MakeSeasonRange($year){ global $_SEASONS_INTERVALS; if ($_SEASONS_INTERVALS[$year]){ list($name,$start,$end) = $_SEASONS_INTERVALS[$year]; } else{ $start = $year."-"._START_SEASON_DEFAULT; $end = $year."-"._END_SEASON_DEFAULT; } return array($start, $end); } function GetSeasonName($year){ global $_SEASONS_INTERVALS; if ($_SEASONS_INTERVALS[$year]){ return $_SEASONS_INTERVALS[$year][0]; }else return $year; } function GetSeasonCode($year){ return str_replace("/","",GetSeasonName($year)); } function GetDatesLimits($year){ list($start_date, $end_date) = MakeSeasonRange($year); if(IsTimeAfter(GetFormatedStringDateNow(), $end_date)) $past_end_date =$end_date; else $past_end_date =GetFormatedStringDateNow(); if(IsTimeAfter(GetFormatedStringDateNow(), $start_date)) $future_start_date =GetFormatedStringDateNow(); else $future_start_date = $start_date; return array ($start_date, $end_date, $future_start_date, $past_end_date); } function SeasonsMenu2XML($year,$objxml){ $xmlStates = AddElementInXML($objxml,"seasons"); for ($i = $year-2;$i <= $year+2; $i++){ AddXMLSeason($i,$xmlStates); } } function AddXMLSeason($year,$xmlStates){ global $_SEASONS_INTERVALS; if ($_SEASONS_INTERVALS[$year]){ $season_name = $_SEASONS_INTERVALS[$year][0]; } else $season_name = $year; if (!$physical_exam_type=$_SEASONS_INTERVALS[$year][3]) $physical_exam_type = _SEASON_PHYSICAL_EXAME_MULTIPLE; if ($season_name){ $xmlState = AddElementInXML($xmlStates,"year"); AddElementInXML($xmlState,"year", $year); AddElementInXML($xmlState,"season",$season_name); AddElementInXML($xmlState,"physical_exam_type",$physical_exam_type); } } function SeasonsMenu2XML2($year, $xml){ $xmlSeason = AddElementInXML($xml,"season"); $new_year = $year-1; AddElementInXML($xmlSeason,"text",$new_year."/".$year); AddElementInXML($xmlSeason,"year",$new_year); $xmlSeason = AddElementInXML($xml,"season"); SetAttributeInXML($xmlSeason,"selected","yes"); $new_year = $year+1; AddElementInXML($xmlSeason,"text",$year."/".$new_year); AddElementInXML($xmlSeason,"year",$year); $xmlSeason = AddElementInXML($xml,"season"); $new_year = $year+1; $new_year2 = $year+2; AddElementInXML($xmlSeason,"text",$new_year."/".$new_year2); AddElementInXML($xmlSeason,"year",$new_year); } function SelectLastYearFromSeason($date,$year=null){ if(!$year) $year = SelectSeasonYearFromDate($date); list(,$end) = MakeSeasonRange($year); $mydate = new _DateTime($end); return $mydate->GetYear(); } function SelectSeasonYearFromToday(){ $date = new _DateTime(); $date->SetDateNow(); return SelectSeasonYearFromDate($date); } function SelectSeasonYearFromDate($date){ global $_SEASONS_INTERVALS; $date_str = MakeStrDateDB($date->day,$date->month, $date->year); foreach ($_SEASONS_INTERVALS as $year =>$season){ list($name,$start,$end) = $season; if (IsTimeBetween($date_str,$start,$end)){ $ryear = $year; } } if (!$ryear){ $ryear = SelectDefaultSeasonYearFronDate($date); } return $ryear; } function SelectDefaultSeasonYearFronDate($date){ return $date->year; } function SelectYearFromDate($date=null){ //$date is an array with the TimeParts if (!$date) $date = GetTimeParts(_DATE_TIME_NOW); list(,$end) = MakeSeasonRange($date->year - 1); if (IsTimeAfter(MakeStrDateDB($date->day,$date->month, $date->year), $end)) return $date->year; else return $date->year - 1; } function LoginValues2XML($xml){ $xmlLogin= AddElementInXML($xml,"login"); $vars = $_SESSION["session_login_params"]; $all_vars = $_GET + $_POST; if ($vars) $all_vars = $all_vars + $vars; foreach ($all_vars as $var_name => $var_value){ if (is_array($var_value)){ foreach ($var_value as $sub_var_value){ $xmlvar= AddElementInXML($xmlLogin,"var"); AddElementInXML($xmlvar,"name", $var_name."[]"); AddElementInXML($xmlvar,"value", $sub_var_value); } }else{ $xmlvar= AddElementInXML($xmlLogin,"var"); AddElementInXML($xmlvar,"name", $var_name); AddElementInXML($xmlvar,"value", $var_value); } } if (!$all_vars["nextscript"]){ if (!($nsvalue = $_SESSION["session_login_script"]) && !getVarPassed("nextscript",_TYPE_SCRIPT)){ $nsvalue = basename ($_SERVER["PHP_SELF"]); } $xmlvar= AddElementInXML($xmlLogin,"var"); AddElementInXML($xmlvar,"name", "nextscript"); AddElementInXML($xmlvar,"value", $nsvalue); } } function AddArgumentInXML($xml,$name,$value){ $xmlAttribute = AddElementInXML($xml, "argument"); AddElementInXML($xmlAttribute, "name",$name); AddElementInXML($xmlAttribute, "value",$value); } /* function clone($object){ return $object; } */ function AddXMLClassFeeTypes($xml){ global $CLASS_FEE_TYPES; while (list($typeid,$str_lng) = each($CLASS_FEE_TYPES)) { $xmlState = InsertGlobalInXML($xml,"class_fee_types"); AddElementInXML($xmlState,"typeid", $typeid); AddElementInXML($xmlState,"description", $str_lng); } } function AddXMLPageNumbers($xml,$start,$end,$quantity,$pagenum=null){ for($i=$start,$j=1; $i<=$end;$i=$i+$quantity,$j++){ $xmlState = InsertGlobalInXML($xml,"page_number"); AddElementInXML($xmlState,"page", $j); AddElementInXML($xmlState,"quantity", $quantity); } if ($pagenum) AddElementInXML($xml,"page_number",$pagenum); } function MakeMethodsList($methods_list =null){ if (!$methods_list) return array(""); else{ $a = array(); foreach ($methods_list as $value) { if($value){ if (!is_array($value)){ $value = array($value); } array_push($a, $value); } } return $a; } } function CreateNonContentXML(){ global $objSuper,$TEMPLATE_ACTIVE,$via; if ($via == _PUBLIC) include_once("public_non_content.php"); else include_once("private_non_content.php"); AddElementInXML($objSuper, "template_active", $TEMPLATE_ACTIVE); } function Redirect2($to){ $schema = $_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http'; $host = strlen($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:$_SERVER['SERVER_NAME']; if (headers_sent()){ return false; } else{ //header("HTTP/1.1 301 Moved Permanently"); header("HTTP/1.1 302 Found"); // header("HTTP/1.1 303 See Other"); //header("Location: $schema://$host/$HOME/$to"); header("Location: $to"); exit(); } } function StartSession(){ global $via; //session_cache_limiter('private'); //session_cache_expire(1); //session_set_cookie_params(60*60); session_start("orioasis"); //setcookie(session_name(),session_id(),time()+60*1); $user = $_SESSION['user_session']; if (!$_SESSION['level_session'] || !$user){ $_SESSION['level_session']=_PUBLIC; $via = _PUBLIC; $_SESSION['level_current_session'] = _PUBLIC; }else{ $via = $_SESSION['level_current_session']; } //$lang = getVarPassed("lang", _TYPE_LANG); if ($lang){ $_SESSION['language'] = $lang; setcookie("oasis_language",$lang); }else{ $lang = GetLanguage(); } require_once(LanguageFile($lang)); if ($_SESSION["session_login_params"]){ $_GET = $_GET + $_SESSION["session_login_params"]; $_POST = $_POST + $_SESSION["session_login_params"]; $_SESSION["session_login_params"]=null; } } function UpdateClubNumMembers(){ /* $SQL_query="UPDATE clubs SET num_members=0"; ExecuteSQLQuery($SQL_query); $SQL_query="SELECT count(*) AS num_members , clubs.clubid FROM users, clubs WHERE users.clubid=clubs.clubid GROUP BY clubid"; $RecSet_query=ExecuteSQLQuery($SQL_query); while($recset = mysql_fetch_array($RecSet_query, MYSQL_ASSOC)){ $club = new Club($recset["clubid"]); $club->SetNumMembers($recset["num_members"]); $club->NumMembers2DB(); } */ UpdateClubsNumMembers(); } function SetNumber(&$a,$key,&$b){ $a->number = $b++; } function SetNumbersInList(&$list,$num=1){ array_walk($list,"SetNumber", $num); } // obj can be CLASS or CLUB function SetNumbersInEntries(&$obj, $key,&$num){ SetNumbersInList($obj->entries,$num); } function LoadEditorEditableEntriesFromDB(&$editor,$results,$eventid,$methods_list,$edit_entries_list ){ global $LOAD_ALL_ENTRIES_FROM_EDITABLE_ENTRIES; $event = &$editor->GetEvent(); if ($edit_entries_list[0]==$LOAD_ALL_ENTRIES_FROM_EDITABLE_ENTRIES){ //Search for USERIDs with entries and fill their eeid $new_res = array(); $userids_index = array(); foreach ($results as $key => $recset) { if (!$recset["eeid"] && $recset["userid"]){ array_push($new_res,"userid=".$recset["userid"]); $userids_index[$recset["userid"]]=$key; } } if (count($new_res)){ $SQL_query = "SELECT DISTINCT userid,eeid ". "FROM entries_event WHERE eventid=$eventid AND (".join(" OR ",$new_res).")"; $RecSet_query=ExecuteSQLQuery($SQL_query); while($recset = mysql_fetch_array($RecSet_query, MYSQL_ASSOC)){ $results[$userids_index[$recset["userid"]]]["eeid"]=$recset["eeid"]; } } } foreach ($results as $recset) { $entry = new EntryEvent($recset['eeid'],$recset['userid'],$eventid,null); //$entry->LoadMainInfoFromDB($methods_list); if (!$recset['eeid'] && !$recset['userid']) $entry->name=$recset['name']; else { $entry->LoadMainInfoFromRecord($recset); /* Entry should be loaded because: 1. Is in entries-list to be loaded 2. Is a new fast entry 3. All entries in event should be loaded (group entry) */ if ($entry->IsEntryInList($edit_entries_list) || $entry->userid_eeid == _ENTRY_EDIT_FAST_NEW || ($entry->eeid && $edit_entries_list[0]==$LOAD_ALL_ENTRIES_FROM_EDITABLE_ENTRIES)){ $entry->LoadMainInfoFromDB($methods_list); $entry->SetEvent($event); $entry->LoadEntriesInfoFromDB($methods_list,null,_LOAD_ENTRY_DATE); $entry->CallMethods($methods_list); //$entry->CalculateIsCancelableEditable(); if ($entry->userid){ $entry->LoadUserFromDB($methods_list); $entry->user->LoadClassesInfoFromDB(); $entry->ValidateInsurance(); } } } $editor->AddEditableEntry($entry); } } function EditorEditableEntries2XML($editor,$xml,$show_entries_list){ foreach ($editor->editable_entries as $entry) { $xmlU = AddElementInXML($xml, "editable_entry"); $entry->AllInfo2XML($xmlU); if ($entry->IsEntryInList($show_entries_list) || $entry->userid_eeid == _ENTRY_EDIT_FAST_NEW){ AddElementInXML($xml, "show_entry", $entry->userid_eeid); } } } function AddXMLEntriesStates($objxml, $via_org){ global $ENTRIES_STATES_ADMIN,$ENTRIES_STATES_DESCRIPTION; if ($via_org ==_ENTRIES_STATE_VALIDATED) $es = $ENTRIES_STATES_DESCRIPTION; else $es = $ENTRIES_STATES_ADMIN; $xmlESs = AddElementInXML($objxml,"entries_states"); foreach ($es as $id => $str_lng) { $xmlES = AddElementInXML($xmlESs,"entry_state"); AddElementInXML($xmlES,"stateid", $id); AddElementInXML($xmlES,"text", $str_lng); } } function GenerateNextMTageID($eventid){ $SQL_query="SELECT max(mtageid) as max_mtageid FROM entries WHERE eventid=$eventid"; $RecSet_query=ExecuteSQLQuery($SQL_query); $recset = mysql_fetch_array($RecSet_query, MYSQL_ASSOC); return max(intval($recset['max_mtageid'])+1,_MTAGEID_START); } function InitializeMethodsList(){ return $methods_list = array("club"=>array(), "entry"=>array(), "entryevent"=>array(), "classevent"=>array(), "user"=>array()); } function AutenticateLoggedUser($userid,$via,$eventid=null,$via_org=null,$admin_event=null){ global $SYSTEM_DETAIL_INVALID_USER_LEVEL, $SYSTEM_DETAIL_INVALID_EVENT_ADMIN; if (!$userid){ //Redirect2RestictedAccess($SYSTEM_DETAIL_INVALID_USER_LEVEL); Redirect2Login(); } $user = new User($userid); $user->LoadMainInfoFromDB(); $user->LoadSystemInfoFromDB(); AutenticateLevel($via); if ($admin_event){ if ($via_org == _ENTRIES_STATE_AWAITING_ORGANIZATION && $user->level<_ADMIN){ Redirect2RestictedAccess($SYSTEM_DETAIL_INVALID_USER_LEVEL); }elseif (!$via_org || ($via_org == _ENTRIES_STATE_VALIDATED && !$user->IsAdminOfEvent($eventid))){ Redirect2RestictedAccess($SYSTEM_DETAIL_INVALID_EVENT_ADMIN); } } } function ValidateVariables($vars){ foreach ($vars as $var){ list($fuction,$args) = $var; if (!call_user_func_array($fuction,$args)) Redirect2RestictedAccess(); } } function float($str){ return floatval(str_replace(',', '.', $str)); } function LoadSelectedEntriesFromForm(){ $total_entries = getVarPassed("total_entries",_TYPE_INTEGER); $entries = array(); for($i=1; $i<=$total_entries; $i++) { if (getVarPassed("select_$i",_TYPE_CHAR)){ $ee = new EntryEvent(getVarPassed("eeid_$i",_TYPE_EEID)); array_push($entries,$ee); } } return $entries; } function LoadAllEntriesFromForm($selected=false){ $total_entries = getVarPassed("total_entries",_TYPE_INTEGER); $entries = array(); for($i=1; $i<=$total_entries; $i++){ if (!$selected || getVarPassed("select_$i",_TYPE_CHAR)){ $ee = new EntryEvent(getVarPassed("eeid_$i",_TYPE_EEID),null,null,getVarPassed("clubid_$i",_TYPE_CLUBID)); $ee->SetPaid(getVarPassed("paid_$i",_TYPE_EURO)); $date = getVarPassed("paid_date_$i",_TYPE_DATETIME); $ee->state = getVarPassed("state_$i",_TYPE_INTEGER); $ee->payment_type = getVarPassed("payment_type_$i",_TYPE_CHAR); $ee->paymentid = getVarPassed("paymentid_$i",_TYPE_CHAR); if ($date){ $date .= ":00"; $date = new _DateTime($date); $ee->SetPaidDate($date); } array_push($entries,$ee); } } return $entries; } function Date2XML($xml,$date,$tag){ if ($date){ $xmlDate = AddElementInXML($xml,$tag); $date->MainInfo2XML($xmlDate); } } function MakeStrHoursMinutes($m,$h){ return intval($h).":".$m; } function MakeStrMinutesSeconds($m,$s){ return intval($m).":".$s; } function Tree2XML($xml,$list,$tag,$name_labels,$desc_label,$level=1){ $xmlTT = AddElementInXML($xml,$tag."s"); foreach ($list as $key => $value) { $xmlNode = AddElementInXML($xmlTT,$tag); if (is_array($value)){ Tree2XML($xmlNode,$value,$tag,$name_labels,$desc_label,$i+1); }else{ $key=$value; } AddElementInXML($xmlNode,"type",$key); AddElementInXML($xmlNode,"name",$name_labels[$key]); AddElementInXML($xmlNode,"description",$desc_label[$key]); AddElementInXML($xmlNode,"level",$level); } } function GetEmailLink($email){ return ''; } function SearchUsers($xmlContent,$extra_filters =null,$methods=null,$vars=null,$query_type=null){ global $objSuper,$via,$action,$USER_REG_DATE_BEFORE,$USER_REG_DATE_AFTER, $LOGIN_CHANGE_USER; LoadClass("system"); LoadClass("club"); LoadClass("date_time"); $registration_date = getVarPassed('user_registration_date_year',_TYPE_YEAR)."-".getVarPassed('user_registration_date_month',_TYPE_MONTH)."-".getVarPassed('user_registration_date_day',_TYPE_DAY); $clubid = getVarPassed('user_clubid',_TYPE_CLUBID); if ($clubid){ LoadClass("address"); $club = new Club($clubid); $club->LoadAddressInfoFromDB(); if ($club->GetCountryCode()) SetVariableInPost("club_country_code",$club->GetCountryCode()); } $order = getVarPassed("order",_TYPE_CHAR,null,null,null,$vars); $active = getVarPassed("active",_TYPE_CHAR,null,null,null,$vars); $userid = getVarPassed("user_userid",_TYPE_USERID); $name = getVarPassed("user_name",_TYPE_NAME,null,null,_CLEAR_STRING_DELIMITERS); $username = getVarPassed("username",_TYPE_USERNAME,null,null,_CLEAR_STRING_DELIMITERS); $email = getVarPassed("user_email",_TYPE_EMAIL,null,null,_CLEAR_STRING_DELIMITERS); if (!$club_country_code = getVarPassed("club_country_code",_TYPE_COUNTRY_CODE)) $club_country_code = _COUNTRY_CODE_DEFAULT; if (getVarPassed("user_license",_TYPE_LICENSE,null,null,null,null,true)){ $license = new UserLicense(null,getVarPassed("user_license",_TYPE_LICENSE), getVarPassed("license_provider",_TYPE_LICENSE_PROVIDER)); } $level = getVarPassed("user_levelid",_TYPE_USER_LEVEL); $iddoc = getVarPassed("user_iddoc",_TYPE_IDDOC); $responsable_userid = getVarPassed("responsable_userid",_TYPE_USERID); $bd_year = getVarPassed("user_birthdate_year",_TYPE_YEAR); $bd_month = getVarPassed("user_birthdate_month",_TYPE_MONTH); $bd_day = getVarPassed("user_birthdate_day",_TYPE_DAY); if ($bd_day && $bd_year && $bd_month) $birthdate = MakeStrDateDB($bd_day,$bd_month,$bd_year); AddElementInXML($objSuper,"user_userid", $userid); AddElementInXML($objSuper,"via", $via); AddElementInXML($objSuper,"action", $action); AddElementInXML($objSuper,"clubid", $clubid); AddElementInXML($objSuper,"user_name", $name); AddElementInXML($objSuper,"username", $username); AddElementInXML($objSuper,"user_email", $email); AddElementInXML($objSuper,"user_birthdate_day", $bd_day); AddElementInXML($objSuper,"user_birthdate_month", $bd_month); AddElementInXML($objSuper,"user_birthdate_year", $bd_year); AddElementInXML($objSuper,"club_country_code", $club_country_code); if ($license){ $xmlLicense = AddElementInXML($objSuper,"user_license"); $license->MainInfo2XML($xmlLicense); } AddElementInXML($objSuper,"user_level", $level); AddElementInXML($objSuper,"user_iddoc", $iddoc); AddElementInXML($objSuper,"responsable_userid", $responsable_userid); $page=getVarPassed("page",_TYPE_INTEGER); if (!$page) $page = 1; $quantity=getVarPassed("quantity",_TYPE_INTEGER); if (!$quantity) $quantity=30; AddElementInXML($objSuper,"page_number", $page); AddElementInXML($objSuper,"quantity_per_page", $quantity); AddElementInXML($objSuper,"order", $order); $date = new _DateTime($registration_date); if ($date->IsValidDate() && getVarPassed('user_registration_date_type',_TYPE_USER_REG_DATE_TYPE)){ if (getVarPassed('user_registration_date_type',_TYPE_USER_REG_DATE_TYPE)==$USER_REG_DATE_BEFORE) $registration_date = "<='$registration_date'"; if (getVarPassed('user_registration_date_type',_TYPE_USER_REG_DATE_TYPE)==$USER_REG_DATE_AFTER) $registration_date = ">='$registration_date'"; } else $registration_date = null; $system = new System(); list($num_members, $total_members) = $system->LoadUsersByInfoFromDB($page, $quantity, $email,$username,$license,$name,$level, $clubid,$iddoc,$birthdate, $registration_date,$responsable_userid,null,$extra_filters,$order,$methods,$active,$userid); $objUsers=AddElementInXML($objSuper,"users"); $system->Users2XML($objUsers); if (!$query_type){ $xmlClubs = AddElementInXML($objSuper,"clubs"); $system->LoadClubsInfoFromDB(null,null,null,null,null,null,$club_country_code); $system->ClubsInfo2XML($xmlClubs); } AddXMLUserLevels($objSuper,$via); AddXMLDateTime(GetXMLGlobalsNode($objSuper),true); AddXMLLicenseProviders($objSuper); AddXMLPageNumbers($objSuper,1,$total_members,$quantity); AddXMLCountries($objSuper, $system->GetClubCountries(null,true)); Orders2XML($objSuper); InsertGlobalInXML($objSuper,"via_super", _SUPER); InsertGlobalInXML($objSuper,"via_admin", _ADMIN); InsertGlobalInXML($objSuper,"login_change_user",$LOGIN_CHANGE_USER); InsertGlobalInXML($objSuper,"delete",_USER_DELETE); InsertGlobalInXML($objSuper,"license_view_user",_LICENSE_VIEW_USER); InsertGlobalInXML($objSuper,"view_user",_ENTRY_VIEW_USER); InsertGlobalInXML($objSuper,"users_search",_USERS_SEARCH); InsertGlobalInXML($objSuper,"pass_update_send",_RECOVER_PASS_UPDATE_AND_SEND); InsertGlobalInXML($objSuper,"view_logs",_USERS_VIEW_LOGS); InsertGlobalInXML($objSuper,"list_all",_LIST_ALL); return $system->users; } function SearchClubs($xmlContent,$methods=null,$with_system_clubs=true,$with_virtual_clubs=true,$type=null){ global $objSuper,$eventid; $order= getVarPassed("order",_TYPE_CHAR); $name = getVarPassed("club_name", _TYPE_NAME); $nick =getVarPassed("club_nick",_TYPE_NAME); $with_club_admin = getVarPassed("club_admin",_TYPE_CHAR); $country_code = getVarPassed("club_country_code",_TYPE_COUNTRY_CODE); $region_code = getVarPassed("club_region_code",_TYPE_REGION_CODE); $without_license = getVarPassed("without_license",_TYPE_CHAR); if (getVarPassed("club_license",_TYPE_LICENSE) || getVarPassed("license_provider",_TYPE_LICENSE_PROVIDER)){ $license = new ClubLicense(null,getVarPassed("club_license",_TYPE_LICENSE), getVarPassed("license_provider",_TYPE_LICENSE_PROVIDER)); } if (!$type) $type = getVarPassed("club_type",_TYPE_CLUB_TYPE); $system = new System(); if (getVarPassed("license_provider",_TYPE_LICENSE_PROVIDER)==_LICENSE_PROVIDER_FPO){ $system->LoadClubInfoFromDB(_CLUBID_INDIVIDUAL_POR_FED); $system->ClubsInfo2XML($xmlContent); } $system = new System(); $system->LoadClubsInfoFromDB($type,$methods,$eventid,$order,$name,$nick,$country_code,$license,$with_system_clubs,$with_club_admin,$region_code,$without_license); $system->ClubsInfo2XML($xmlContent); AddElementInXML($objSuper,"club_name", $name); AddElementInXML($objSuper,"club_nick", $nick); AddElementInXML($objSuper,"club_country_code", $country_code); AddElementInXML($objSuper,"club_region_code", $region_code); if ($license){ $xmlLicense = AddElementInXML($objSuper,"club_license"); $license->MainInfo2XML($xmlLicense); } AddElementInXML($objSuper,"with_club_admin", $with_club_admin); AddXMLLicenseProviders($objSuper); AddXMLCountries($objSuper, $system->GetClubCountries($eventid,$with_system_clubs,$type)); InsertGlobalInXML($objSuper,"list_all",_LIST_ALL); } function Orders2XML($xml){ global $ORDER_BY_USER_LICENSE,$ORDER_BY_USERS_NAME,$ORDER_BY_BIRTH_DATE, $ORDER_BY_USERID; InsertGlobalInXML($xml,"order_by_userid",$ORDER_BY_USERID); InsertGlobalInXML($xml,"order_by_license",$ORDER_BY_USER_LICENSE); InsertGlobalInXML($xml,"order_by_users_name",$ORDER_BY_USERS_NAME); InsertGlobalInXML($xml,"order_by_birth_date",$ORDER_BY_BIRTH_DATE); InsertGlobalInXML($xml,"order_by_club_nick",_ORDER_BY_CLUB_NICK); } function FixStringDelimiters($str){ return str_replace (array("\\\"","\\'","\\\\"),array("\"","'","\\"), $str); } function EscapeString($str){ return str_replace ("'","\\'", $str); } function ReplaceStringDelimiters($str){ return str_replace (array("\"","'","\\")," ", $str); } function FixStringDelimiters2DB($str){ return str_replace(array("'","\\n","\\"),array(_SINGLE_QUOTE,_NL,_BACKSLASH),$str); } function FixLines2String($str){ return str_replace (array("\r\n","\n"),_NL, $str); } function FixString2Lines($str){ return str_replace (_NL,"\r\n", $str); } function Value2SQL($value){ if (!$value) return "NULL"; else return "'".FixStringDelimiters2DB($value)."'"; } function FixStringDelimitersFromDB($str){ // removed on 2009-05-22 //return stripslashes(str_replace(array("__SINGLE_QUOTE__","__NEW_LINE__"),array("'","\\n"),$str)); return str_replace(array(_SINGLE_QUOTE,_NL,_BACKSLASH),array("'","\\n","\\"),$str); } function ItemsList2XML($xml,$via,$action,$clubid,$responsable_userid=null){ global $ORDER_BY_USERID,$ORDER_BY_USER_LICENSE,$ORDER_BY_USERS_NAME, $ORDER_BY_BIRTH_DATE,$USERS_COMMUNITY,$ORDER_BY_ASSOCIATE; $xmlList = AddElementInXML($xml,"items_list"); if ($action== _USERS_SEARCH){ $xmlUserID = AddElementInXML($xmlList,"userid","UserID"); SetAttributeInXML($xmlUserID,"order",$ORDER_BY_USERID); } $xmlName = AddElementInXML($xmlList,"name","Nome"); SetAttributeInXML($xmlName,"order",$ORDER_BY_USERS_NAME); if ($via>=_NORMAL || $clubid==$logged_clubid){ $xmlBirth = AddElementInXML($xmlList,"birthdate","Nasc."); SetAttributeInXML($xmlBirth,"order",$ORDER_BY_BIRTH_DATE); } $xmlLicense = AddElementInXML($xmlList,"license","Lic."); SetAttributeInXML($xmlLicense,"order",$ORDER_BY_USER_LICENSE); if ($action== _USERS_SEARCH || $action==$USERS_COMMUNITY){ $xmlClub = AddElementInXML($xmlList,"si","SI"); } if ($action== _USERS_SEARCH){ $xmlClub = AddElementInXML($xmlList,"club","Clube"); SetAttributeInXML($xmlClub,"order",_ORDER_BY_CLUB_NICK); } $xmlName = AddElementInXML($xmlList,"level","Nível Acesso"); SetAttributeInXML($xmlName,"order",_ORDER_BY_LEVEL); $logged_clubid = $_SESSION['club_session']; if (($action== $USERS_COMMUNITY || $action== _CLUB_VIEW) && ($clubid==$logged_clubid || $via==_SUPER)){ $xmlAssociate = AddElementInXML($xmlList,"associate","Sócio"); SetAttributeInXML($xmlAssociate,"order",$ORDER_BY_ASSOCIATE); AddElementInXML($xmlList,"address","Morada"); AddElementInXML($xmlList,"email","e-Mail"); AddElementInXML($xmlList,"telephone","Telefone"); }elseif ($via>=_ADMIN || $responsable_userid){ AddElementInXML($xmlList,"personal_info","Pes."); AddElementInXML($xmlList,"access_info","Aces."); AddElementInXML($xmlList,"system_info","Sis."); AddElementInXML($xmlList,"trust_info","Conf."); AddElementInXML($xmlList,"entries_info","Insc."); AddElementInXML($xmlList,"classes_info","Esc."); AddElementInXML($xmlList,"send_info","Env."); if ($via >= _SUPER){ AddElementInXML($xmlList,"licenses_info","Lic."); AddElementInXML($xmlList,"doma_info","Doma"); } AddElementInXML($xmlList,"login_info","In"); AddElementInXML($xmlList,"logs_info","Log"); AddElementInXML($xmlList,"delete_info"); } } function Labels2XML($xml){ global $LABELS; $xmlLang = AddElementInXML($xml,"lang"); foreach ($LABELS as $key=>$label) { AddElementInXML($xmlLang,$key,$label); } } function Language2XML($xml){ $LANG = get_defined_constants(); $xmlLang = AddElementInXML($xml,"lang"); foreach ($LANG as $key=>$label) { if ($label && substr($key,0,5)=="_LANG"){ //AddElementInXML($xmlLang,substr($key,5),htmlspecialchars($label,null,"ISO-8859-15")); AddElementInXML($xmlLang,substr($key,5),$label); } } AddElementInXML($xmlLang,"langvar",GetLanguage()); } function ReadLicensesFromStr($licenses){ $licenses = str_replace(",", " ",$licenses); $licenses = str_replace("\r\n", " ",$licenses); $licenses = str_replace("\n", " ",$licenses); return str_replace(";", " ",$licenses); //return split(" ",$licenses); } function AddXMLLicenseProviders($xml){ global $LICENSES_PROVIDERS; $xmlProviders = AddElementInXML($xml,"licenses_providers"); foreach ($LICENSES_PROVIDERS as $key=>$name) { $xmlProvider = AddElementInXML($xmlProviders,"licenses_provider"); AddElementInXML($xmlProvider,"providerid",$key); AddElementInXML($xmlProvider,"name",$name); } } function SetEventEntriesQuantity($stagen,$quantity,$num_stages,$obj,$state=null,$total_clubs=null){ if (!is_numeric($stagen)){ // TOTAL ENTRIES OF THE CLUB (STAGEN = 0) if ($quantity) $obj->total_entries = $quantity; if ($total_clubs)$obj->total_clubs = $total_clubs; $obj->SetEntriesState($state); if ($obj->event){ while ($obj->event->GetNumStages() < $num_stages){ $obj->event->AddStage(new Stage()); } } } else{ if (!$obj->event){ $obj->event = new Event(); } while ($obj->event->GetNumStages() < $stagen-1){ $obj->event->AddStage(new Stage()); } $stage = &$obj->event->GetStage($stagen); if (!$stage){ $stage = new Stage(null,$stagen); $obj->event->AddStage($stage); } if ($quantity) $stage->SetTotalEntries($quantity); if ($total_clubs) $stage->SetTotalClubs($total_clubs); } } function CanAdminUser($userid,$logged_user=null){ if (!$logged_user) $logged_user = $_SESSION["user_session"]; if (!$logged_user) Redirect2RestictedAccess(); $logged_user->AuthorizeOperationOnUser($userid); } function AddXMLUserLevels($xml,$via){ $user_levels = array(); $user_levels[_NORMAL]="NORMAL"; if ($via >= _ADMIN){ $user_levels[_ADMIN]="CLUBE-ADMIN"; if ($via == _SUPER){ $user_levels[_SUPER]="SUPER-USER"; } } $xmlLevels = AddElementInXML(GetXMLGlobalsNode($xml),"levels"); while (list($levelid,$levelstr) = each($user_levels)){ $xmlLevel = AddElementInXML($xmlLevels,"level"); AddElementInXML($xmlLevel,"levelid", $levelid); AddElementInXML($xmlLevel,"levelstr", $levelstr); } } function FormatFee($fee){ $fee = float($fee); $dec = abs(intval(float(($fee-intval($fee))*100))); $str = intval($fee).",".C2DigitStr($dec); if ($fee<0 && intval($fee)==0) $str = "-".$str; return $str; } function PrintTimeNow($msg=null){ list($usec, $sec) = explode(" ", microtime()); echo date("H:i:s",$sec). ",$usec ". $msg . "
\n"; } function ExistsURL($url){ $url = str_replace("http://", "", $url); if (strstr($url, "/")) { $url = explode("/", $url, 2); $url[1] = "/".$url[1]; } else { $url = array($url, "/"); } if (IsURL($url[0])){ $fh = fsockopen($url[0], 80); if ($fh) { fputs($fh,"GET ".$url[1]." HTTP/1.1\nHost:".$url[0]."\n\n"); if (fread($fh, 22) == "HTTP/1.1 404 Not Found") { return FALSE; } else { return TRUE; } } } } function GetLinkedURL($val,$display=null){ $val = trim($val); if (!$display) $display = $val; $val = SetURLHTTP($val); if (IsURL($val)){ $val = ''.$val.''; } return $val; } function IsURL($val){ $regexp = '/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/i'; //$regexp = '/^(https?:\/\/)[a-z0-9-]+(\.[a-z0-9-]+)+$/i'; return preg_match($regexp, $val); } function IsURLWithoutProtocol($val){ $regexp = '/^(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/i'; //$regexp = '/^(https?:\/\/)[a-z0-9-]+(\.[a-z0-9-]+)+$/i'; return preg_match($regexp, $val); } function SetURLHTTP($val){ if ($val && substr($val,0,4)!="http" && IsURLWithoutProtocol($val)){ $val = "http://".$val; } return $val; } function GetDisciplinCalendars2($disciplinid){ global $EVENT_CALENDAR_DISCIPLIN; $calendars = array(); foreach ($EVENT_CALENDAR_DISCIPLIN as $cid => $cdid){ if ($disciplinid==$cdid) array_push($calendars,$cid); } return $calendars; } function GetDisciplinCalendars($disciplinid){ $calendars = array(); $SQL_query="SELECT calendarid FROM calendars WHERE disciplinid=$disciplinid"; $RecSet_query=ExecuteSQLQuery($SQL_query); while($recset = mysql_fetch_array($RecSet_query, MYSQL_ASSOC)){ array_push($calendars,$recset["calendarid"]); } return $calendars; } function DisplayError($message){ loadClass("error"); if (_DEBUG_MODE=="on") echo $message; $error = new SystemError($message); if ($error->DisplayError()) echo "
There was an error and it was written to log!
"; } function ClearSessionVars(){ $_SESSION['userid_session']=""; $_SESSION['pwd_md5_session']=""; $_SESSION['level_session']=""; $_SESSION['club_session']=""; } function AddOptions2XML($xml,$node_name,$values,$in_global_xml=true){ if($in_global_xml){ $xml = GetXMLGlobalsNode($xml); } if ($values){ foreach ($values as $key => $value) { $xmlState = AddElementInXML($xml,$node_name); AddElementInXML($xmlState,"text",$value); AddElementInXML($xmlState,"id",$key); } } } function LicenseRankingsDefault2XML($xml){ global $_LICENSE_RANKINGS_DEFAULT; $values = $_LICENSE_RANKINGS_DEFAULT; if ($values){ foreach ($values as $key => $value) { list($calendarid,$col) = $value; $xmlState = AddElementInXML($xml,"class_ranking"); AddElementInXML($xmlState,"calendarid",$calendarid); AddElementInXML($xmlState,"column",$col); AddElementInXML($xmlState,"number",$key); } } } function GetNextSQLQueryResultRow($result){ if ($result){ return mysql_fetch_array($result, MYSQL_ASSOC); } } function AddEventTaskBar($objEvent,$is_event_admin,$via,$clubid=null,$eeid=null){ global $objSuper, $action,$logged_user; $xmlQL = AddElementInXML($objSuper,"quick_links"); if ($objEvent){ $eventid = $objEvent->GetEventID(); if ($objEvent->GetHomepageState()==_HOMEPAGE_EVENT_STATE_ACTIVE || $objEvent->GetHomepageState()==_HOMEPAGE_EVENT_STATE_ACTIVE_HIDDEN || $is_event_admin){ AddElementInXML($xmlQL,"homepage_img_link"); if ($is_event_admin){ AddElementInXML($xmlQL,"homepage_edit_img_link"); } } } AddElementInXML($xmlQL,"event_info_img_link"); AddElementInXML($xmlQL,"view_entries_img_link"); AddElementInXML($xmlQL,"search_entries_img_link"); AddElementInXML($xmlQL,"pay_entries_img_link"); if (!$via || $via == _PUBLIC) { AddElementInXML($xmlQL,"edit_entries_pub_img_link"); }else{ if ($action!=_ENTRY_EDIT) AddElementInXML($xmlQL,"edit_entries_img_link"); if ($action!=_ENTRY_GROUP_EDIT) AddElementInXML($xmlQL,"edit_group_entries_img_link"); } if ($via >= _ADMIN && $clubid && $action!=_ENTRY_EDIT){ AddElementInXML($xmlQL,"edit_my_club_entries_img_link"); } if ($action==_ENTRY_EDIT && $eeid){ } if ($eventid && $is_event_admin){ if ( ($action==_CLUB_EDIT || $action== _CLUB_SUBMIT) && $clubid) AddElementInXML($xmlQL,"edit_entries_event_club_img_link"); AddElementInXML($xmlQL,"edit_clubs_entries_img_link"); AddElementInXML($xmlQL,"validate_entries_img_link"); AddElementInXML($xmlQL,"export_entries_img_link"); AddElementInXML($xmlQL,"search_entries_obs_org_img_link"); AddElementInXML($xmlQL,"express_entries_img_link"); AddElementInXML($xmlQL,"express_entries_add_img_link"); AddElementInXML($xmlQL,"view_event_changelog_img_link"); AddElementInXML($xmlQL,"edit_event_img_link"); AddElementInXML($xmlQL,"add_club_img_link"); AddElementInXML($xmlQL,"view_clubs_img_link"); AddElementInXML($objSuper,"is_event_admin"); //AddElementInXML($xmlQL,"view_entries_express_img_link"); AddElementInXML($xmlQL,"upload_results_img_link"); AddElementInXML($xmlQL,"tools_img_link"); AddElementInXML($xmlQL,"contacts_img_link"); if ($logged_user && $logged_user->GetLevel()==_SUPER){ AddElementInXML($xmlQL,"users_org_img_link"); } AddElementInXML($xmlQL,"list_invoices_img_link"); } AddElementInXML($xmlQL,"view_results_img_link"); AddElementInXML($xmlQL,"events_entries_img_link"); if ($objEvent && $objEvent->HasLocations()) AddElementInXML($xmlQL,"map_img_link"); InsertGlobalInXML($objSuper,"event_view_info",_EVENT_VIEW_INFO); InsertGlobalInXML($objSuper,"entry_edit",_ENTRY_EDIT); InsertGlobalInXML($objSuper,"entry_group_edit",_ENTRY_GROUP_EDIT); InsertGlobalInXML($objSuper,"entries_sync",_ENTRY_SYNC); InsertGlobalInXML($objSuper,"entries_search", _ENTRIES_SEARCH); InsertGlobalInXML($objSuper,"view_club_class",_ENTRY_VIEW_CLUB_CLASS); InsertGlobalInXML($objSuper,"shortcut_clubs",_SHORTCUT_CLUBS); InsertGlobalInXML($objSuper,"shortcut_events",_SHORTCUT_EVENTS); InsertGlobalInXML($objSuper,"club_view",_CLUB_VIEW); InsertGlobalInXML($objSuper,"changelog",_EVENT_VIEW_CHANGE_LOG); InsertGlobalInXML($objSuper,"edit_event",_EVENT_VIEW); InsertGlobalInXML($objSuper,"entries_express",_ENTRIES_EXPRESS); InsertGlobalInXML($objSuper,"event_view_info",_EVENT_VIEW_INFO); InsertGlobalInXML($objSuper,"view_clubs",_CLUBS_VIEW); InsertGlobalInXML($objSuper,"edit_club",_CLUB_EDIT); InsertGlobalInXML($objSuper,"entries_state_validated",_ENTRIES_STATE_VALIDATED); InsertGlobalInXML($objSuper,"register_entry",_GUIDE_REGISTER_ENTRY); InsertGlobalInXML($objSuper,"view_results",_RESULTS_VIEW_STAGES); InsertGlobalInXML($objSuper,"upload_results",_RESULTS_UPLOAD); InsertGlobalInXML($objSuper,"view_map",_EVENT_MAP); InsertGlobalInXML($objSuper,"express_entries",_EVENT_LIST_EXPRESS_ENTRIES); InsertGlobalInXML($objSuper,"entry_express",_ENTRY_EXPRESS); InsertGlobalInXML($objSuper,"context_system",_CONTEXT_SYSTEM); InsertGlobalInXML($objSuper,"contacts",_EVENT_ENTRIES_CONTACTS); InsertGlobalInXML($objSuper,"users_org",_EVENT_USERS_ORGANIZATION); InsertGlobalInXML($objSuper,"event_tools",_EVENT_TOOLS); InsertGlobalInXML($objSuper,"payment_on",_ENTRIES_PAYMENT_ON); InsertGlobalInXML($objSuper,"validate_on",_ENTRIES_VALIDATE_ON); InsertGlobalInXML($objSuper,"invoices_list",_EVENT_INVOICES_LIST); InsertGlobalInXML($objSuper,"homepage_view",_HOMEPAGES_EVENT_VIEW); InsertGlobalInXML($objSuper,"homepage_edit",_HOMEPAGES_EVENT_EDIT); } function AddRankingTaskBar($ranking,$eventid,$stage,$action){ global $objSuper; $logged_user = $_SESSION['user_session']; $xmlQL = AddElementInXML($objSuper,"quick_links"); AddElementInXML($xmlQL,"ranking_list_img_link"); if ($logged_user && $logged_user->GetLevel()==_SUPER){ if ($ranking && $ranking->GetType()==_RANKING_TYPE_DYNAMIC && $ranking->GetCalculateType()!=_RANKING_CALCULATE_TYPE_CLOSED) AddElementInXML($xmlQL,"ranking_stages_img_link"); AddElementInXML($xmlQL,"ranking_edit_img_link"); } AddElementInXML($xmlQL,"ranking_users_img_link"); if ($ranking && $ranking->GetMembersType()==_RANKING_MEMBERS_TYPE_CLUBS && $action!=_RANKINGS_VIEW_STAGE){ if ($eventid && $stage) AddElementInXML($xmlQL,"ranking_stage_img_link"); AddElementInXML($xmlQL,"ranking_mvp_img_link"); } InsertGlobalInXML($objSuper,"ranking_stages",_RANKINGS_STAGES); InsertGlobalInXML($objSuper,"ranking_edit",_RANKINGS_EDIT); InsertGlobalInXML($objSuper,"ranking_users",_RANKINGS_VIEW_USERS); InsertGlobalInXML($objSuper,"ranking_list",_RANKINGS_LIST); InsertGlobalInXML($objSuper,"ranking_mvp",_RANKINGS_VIEW_MVP); InsertGlobalInXML($objSuper,"ranking_con_classes",_RANKINGS_CONNECTION_CLASSES); InsertGlobalInXML($objSuper,"ranking_stage",_RANKINGS_VIEW_STAGE); } function average($array){ return array_sum($array)/count($array) ; } function AddCurrentURL2XML($objSuper,$script=null,$exclude_vars=null,$xml_tag="current_href"){ $args_list = array ("script","action","via","task","via_org","clubid","eventid","userid","sh","action_global","comp","show_details"); $args_list = array ("script","action","task","clubid","eventid","userid","sh","action_global","comp","show_details"); if(!empty($exclude_vars) && is_array($exclude_vars)) $args_list = array_diff($args_list,$exclude_vars); $deep = 1; $xmlCurrent = AddElementInXML($objSuper,$xml_tag); foreach ($args_list as $arg){ $arg_pieces = split(" ",getVarPassed($arg)); if(count(array_filter($arg_pieces))){ $xmlArg = AddElementInXML($xmlCurrent,"argument"); AddElementInXML($xmlArg,"name", $arg); AddElementInXML($xmlArg,"value", str_replace(" ","+",getVarPassed($arg))); AddElementInXML($xmlArg,"value_clear", getVarPassed($arg)); $deep = max($deep,count($arg_pieces)); global $$arg; $$arg = $arg_pieces[0]; unset($arg_pieces[0]); $xmlArg = AddElementInXML($objSuper,"argument"); AddElementInXML($xmlArg,"name", $arg); AddElementInXML($xmlArg,"value", join("+",$arg_pieces)); } } if ($script) AddElementInXML($objSuper,"script",$script); for($i=2; $i<$deep;$i++) $xmlArg = AddElementInXML($objSuper,"level"); } function AddXMLSearchUsersOptions($xml,$script=null,$args=array(),$fields=array()){ $xmlOpts = AddElementInXML($xml,"user_search_form_options"); AddElementInXML($xmlOpts,"script",$script); foreach ($args as $name=>$value) { $xmlArg = AddElementInXML($xmlOpts,"argument"); AddElementInXML($xmlArg,"name",$name); AddElementInXML($xmlArg,"value",$value); } $xmlOpts = AddElementInXML($xml,"user_search_form_fields"); foreach ($fields as $name=>$value){ $xmlField = AddElementInXML($xmlOpts,$name); if ($value) SetAttributeInXML($xmlField,"level",$value); } } function AddInfo2XML($xml,$tag,$info){ $xmlTag = AddElementInXML($xml,$tag); foreach ($info as $name=>$value) { if (is_array($value)){ AddInfo2XML($xmlTag,$name,$value); }else{ AddElementInXML($xmlTag,$name,$value); } } return $xmlTag; } function GetURLContents($url){ $http=new http_class; $http->follow_redirect=1; $http->redirection_limit=5; $http->GetRequestArguments($url,$arguments); $error=$http->Open($arguments); $error=$http->SendRequest($arguments); $http->ReadReplyBody($body,1000000); return $body; } function AddXMLCurrentPath($path){ global $objSuper; $xmlPath = AddElementInXML($objSuper,"current_path"); foreach ($path as $p){ AddElementInXML($xmlPath,"place",$p); } } function GetDateExtensive($date){ global $_LANG_MONTH_NAME,$_LANG_DAY_NAME_LONG,$_LANG_DATE_FORMAT; $date->SetWeekDay(); //return $_LANG_DAY_NAME_LONG[$date->GetWeekDay()]. ", " .intval($date->GetDay()) . " de ". $_LANG_MONTH_NAME[intval($date->GetMonth())] . " de ". $date->GetYear(); $day_name = $_LANG_DAY_NAME_LONG[$date->GetWeekDay()]; $day = intval($date->GetDay()); $month = $_LANG_MONTH_NAME[intval($date->GetMonth())-1]; $year = $date->GetYear(); $date = date($_LANG_DATE_FORMAT); $date = str_replace(array("%A","%e", "%B","%G"),array($day_name,$day,$month,$year),$date); return $date; } function LoadEditorEditableEntriesFromFile($editor,$clubid,$eventid){ //CHANGE CODE $lines = $_FILES['the_file']['tmp_name']; foreach($lines as $line){ $line = trim(split(";",$line)); $event = &$editor->GetEvent(); $entry = new EntryEvent(null,null,$eventid,null); $entry->LoadInfoFromCSVLine(); //$entry->LoadMainInfoFromDB($methods_list); $editor->AddEditableEntry($entry); } } function LoadImageFromFormResizeAndSave($field_name="file",$dir,$file_name,$maxwidth,$maxheight){ if($_FILES[$field_name]) { preg_match('/\.([A-Za-z]+?)$/', $_FILES[$field_name]['name'], $matches); $extension = strtolower($matches[1]); ResizeAndSave($extension,$dir,$file_name,$_FILES[$field_name]['tmp_name'],$maxwidth,$maxheight); } else $error = 'No image uploaded!'; } function ResizeAndSave($extension,$dir,$file_name,$file_path,$maxwidth,$maxheight,$min_size=null){ //$extension = strtolower($extension); //DisplayTimer($file_name); if (IsURL($file_path)){ $content = @file_get_contents($file_path); if ($content) file_put_contents(_IMAGES_CACHE_DIR.$file_name,$content); $file_path = _IMAGES_CACHE_DIR.$file_name; $clean_cache=true; } //DisplayTimer($file_name); $imginfo = @getimagesize($file_path); //DisplayTimer($file_name); list($owidth, $oheight) = $imginfo; if ( ($min_size && ($owidth < $min_size || $oheight < $min_size)) || !$owidth || !$oheight) return; $extension = str_replace("image/","",$imginfo["mime"]); if($extension == 'png' && function_exists('imagecreatefrompng') || $extension == 'jpeg' && function_exists('imagecreatefromjpeg') || $extension == 'gif' && function_exists('imagecreatefromgif') || $extension == 'bmp' && function_exists('imagecreatefromwbmp')) { if ($owidth/$maxwidth > $oheight/$maxheight) $resizeby = "width"; else $resizeby ="height"; if($resizeby == 'height') { $nheight = ($maxheight>1)?$maxheight:600; $nwidth = $nheight / $oheight * $owidth; $resized = imagecreatetruecolor($nwidth, $nheight); } else { $nwidth = ($maxwidth>1)?$maxwidth:800; $nheight = $nwidth / $owidth * $oheight; $resized = imagecreatetruecolor($nwidth, $nheight); } if($extension == 'png') $original = @imagecreatefrompng($file_path); elseif($extension == 'jpeg') $original = @imagecreatefromjpeg($file_path); elseif($extension == 'gif') $original = @imagecreatefromgif($file_path); elseif($extension == 'bmp') $original = @imagecreatefromwbmp($file_path); //DisplayTimer($file_name); if ($original){ if ( ($extension == "gif") || ($extension == "png") ) { $trnprt_indx = imagecolortransparent($original); // If we have a specific transparent color if ($trnprt_indx >= 0) { // Get the original image's transparent color's RGB values $trnprt_color = @imagecolorsforindex($original, $trnprt_indx); // Allocate the same color in the new image resource $trnprt_indx = imagecolorallocate($resized, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']); // Completely fill the background of the new image with allocated color. imagefill($resized, 0, 0, $trnprt_indx); // Set the background color for new image to transparent imagecolortransparent($resized, $trnprt_indx); } // Always make a transparent background color for PNGs that don't have one allocated already elseif ($extension == "png") { // Turn off transparency blending (temporarily) imagealphablending($resized, false); // Create a new transparent color for image $color = imagecolorallocatealpha($resized, 0, 0, 0, 127); // Completely fill the background of the new image with allocated color. imagefill($resized, 0, 0, $color); // Restore transparency blending imagesavealpha($resized, true); } } imagecopyresampled($resized, $original, 0, 0, 0, 0, $nwidth, $nheight, $owidth, $oheight); if ($clean_cache) unlink($file_path); return imagepng($resized,$dir.$file_name); } } else $error = 'File type not supported!'; } function GetImageEncodedFileName($code){ return $code.".".md5($code._IMAGE_FILE_NAME_ENCODE_CODE).".png"; } function LoadImageFromFormResizeAndSave2($field_name="file",$dir,$file,$maxwidth,$maxheight){ $temp_name =$_FILES[$field_name]['tmp_name']; $userfile_name =$_FILES[$field_name]['name']; $userfile_size =$_FILES[$field_name]['size']; $userfile_type =$_FILES[$field_name]['type']; /* $thumb_width=90; $thumb_height=90; $image_width=300; $image_height=400; */ $thumb_width=$maxwidth; $thumb_height=$maxheight; if (!($userfile_type =="image/pjpeg" OR $userfile_type =="image/jpeg" OR $userfile_type=="image/gif" OR $userfile_type=="image/png" OR $userfile_type=="image/x-png")){ die ("You can upload just images in .jpg .jpeg .gif and .png format!
"); } $data = fread(fopen($temp_name, "rb"), filesize($temp_name)); $src_image = imagecreatefromstring($data); $width = imagesx($src_image); $height = imagesy($src_image); if ($thumb_width && ($width < $height)) { $thumb_width = ($thumb_height / $height) * $width; } else { $thumb_height = ($thumb_width / $width) * $height; } if ($image_width && ($width < $height)) { $image_width = ($image_height / $height) * $width; } else { $image_height = ($image_width / $width) * $height; } //$dest_img = imagecreatetruecolor($thumb_width, $thumb_height); $simg = $src_image; $dimg = imagecreate($thumb_width, $thumb_height); // Make New Image For Thumbnail imagetruecolortopalette($simg, false, 256); // Create New Color Pallete $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { // Counting Colors In The Image $colors = ImageColorsForIndex($simg, $i); // Number Of Colors Used ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use } $dest_img = $dimg; //$i_dest_img = imagecreatetruecolor($image_width, $image_height); imagecopyresized($dest_img, $src_image,0, 0, 0, 0,$thumb_width, $thumb_height,$width, $height); //imagecopyresized($i_dest_img, $src_image,0, 0, 0, 0,$image_width, $image_height,$width, $height); //ob_start(); if($userfile_type == "image/jpeg" OR $userfile_type == "image/pjpeg"){ $ext=".jpg"; imagejpeg($dest_img,$dir.$file.$ext); } if($userfile_type == "image/gif"){ $ext=".gif"; imagegif($dest_img,$dir.$file.$ext); } if($userfile_type == "image/png" OR $userfile_type == "image/x-png"){ $ext=".png"; imagepng($dest_img,$dir.$file.$ext); } /* $binaryThumbnail = ob_get_contents(); ob_end_clean(); ob_start(); if($userfile_type == "image/jpeg" OR $userfile_type == "image/pjpeg"){ imagejpeg($i_dest_img); } if($userfile_type == "image/gif"){ imagegif($i_dest_img); } if($userfile_type == "image/png" OR $userfile_type == "image/x-png"){ imagepng($i_dest_img); } $binaryImage = ob_get_contents(); ob_end_clean(); if(!get_magic_quotes_gpc()){ $binaryThumbnail=addslashes($binaryThumbnail); $binaryImage=addslashes($binaryImage); } $blob_arr['image']=$binaryImage; $blob_arr['thumb']=$binaryThumbnail; $blob_arr['type']=$userfile_type; */ } function Sex2XML($xml,$sex){ global $SEX_TYPES; $xmlSex = AddElementInXML($xml,"sex"); AddElementInXML($xmlSex,"sexid", $sex); AddElementInXML($xmlSex,"text", $SEX_TYPES[$sex]); AddElementInXML($xmlSex,"short_text", substr($SEX_TYPES[$sex],0,1)); return $xmlSex; } function ConvertShortSex2ID($sex_short){ global $SEX_TYPES; foreach ($SEX_TYPES as $sexid => $sex_type){ if ($sex_short == substr($sex_type,0,1)) return $sexid; } } function ClearMtageStringDelimiters($str){ return str_replace('"',"",$str); } function SetMtageStringDelimiters($str){ return '"'.$str.'"'; } function SystemDebug($str,$logfile=null){ $error = new SystemError($str); $error->LogDebug($logfile); } function IsHostBlackListed($remote,$agent){ global $_BLACK_LIST_HOST; if ($remote){ foreach ($_BLACK_LIST_HOST["host"] as $host){ if (strstr($remote,$host) ) return true; } foreach ($_BLACK_LIST_HOST["browser"] as $iagent){ if (strstr($agent,$iagent)) return true; } } } function MyPrint($obj){ echo "
".print_r($obj,true)."
"; } function IsObjectOfClass($object,$class){ return strtolower(get_class($object))==strtolower($class); } function SetOutputHeader($mime_type,$out_filename){ header('Content-Type: ' . $mime_type); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // lem9 & loic1: IE need specific headers if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')){ header('Content-Disposition: inline; filename="' . $out_filename . '"'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); } else { header('Content-Disposition: attachment; filename="' . $out_filename . '"'); header('Pragma: no-cache'); } } function CalculateCalendarNames($calendars){ global $EVENT_DISCIPLIN_IMG_URL,$EVENT_DISCIPLIN_DESC; $calendar_names = array(); $added_discplins = array(); $added_calendars= array(); $calendar_names_text = array(); $calendar_names_short_text = array(); $disciplin = ""; foreach ($calendars as $calendar){ if ($calendar){ $disciplin_url = $EVENT_DISCIPLIN_IMG_URL[$calendar->GetDisciplinID()]; if (!$added_discplins[$disciplin_url]){ array_push($calendar_names,''.$calendar->GetName().''); array_push($calendar_names_text,$EVENT_DISCIPLIN_DESC[$calendar->GetDisciplinID()]); $added_discplins[$disciplin_url]=1; if (count($added_discplins) == 1) $disciplin = $EVENT_DISCIPLIN_DESC[$calendar->GetDisciplinID()]; else $disciplin = _EVENT_DISCIPLIN_MULTI_DESC; } $calend_str = ''.$calendar->GetName().''; if ($calendar->GetImageURL() != _EVENT_DISCIPLIN_NO_DESC && !$added_calendars[$calend_str]){ array_push($calendar_names,$calend_str); array_push($calendar_names_text,$calendar->GetName()); array_push($calendar_names_short_text,$calendar->GetNameShort()); $added_calendars[$calend_str]=1; } } } return array(join(" ",array_unique($calendar_names)),join(" ",array_unique($calendar_names_text)),join(" ",array_unique($calendar_names_short_text)),$disciplin); } function CalculateRankingNames($rankings){ $ranking_names_text = array(); foreach ($rankings as $ranking){ if ($ranking){ $ranking_names_text[$ranking->GetNameShort()] = $ranking->GetNameShort(); } } return join(", ",array_unique($ranking_names_text)); } function GetSQLQueryAffectedRows($myDB=false){ global $_DB_SETTINGS; if (!$myDB){ $myDB = _DB_OASIS; } if ($_DB_SETTINGS[$myDB][4]){ $result = mysql_affected_rows($_DB_SETTINGS[$myDB][4]); } else{ DisplayError("
Empty SQL resource.
"); return; } return $result; } function Int2Alpha( $num ) { $anum = ''; while( $num >= 1 ) { $num = $num - 1; $anum = chr(($num % 26)+65).$anum; $num = $num / 26; } return $anum; } function Alpha2Int($alpha_string) { $int_wert=0; $potenzcounter=0; for ($i=strlen($alpha_string);$i>0;$i--) { $ordinalwert=(ord(substr($alpha_string,$i-1,1))-64); $int_wert+=$ordinalwert*pow(26,$potenzcounter); $potenzcounter++; } return $int_wert; } function ParseIP2Country($ip){ $DATABASE = "whois.ripe.net"; $info = '' ; $sk=@fsockopen($DATABASE, 43, $errno, $errstr, 30); //or die ("Unable to connect to the server"); $res = @fputs ($sk, $ip ."\r\n"); // or die ("Unable to send data to the server"); if (!$sk || !$res) return false; while (!feof($sk)) { $info.= fgets ($sk, 2048); } if (preg_match( '/^\x20*country\x20*:\x20*(\w{2})/im',$info,$arr )) { return trim($arr[1]);/* $found=false; for($i=0;$i_COUNTRIES);$i++) { $c=$this->_COUNTRIES[$i]; if (trim($c[0]) == trim($arr[1])) return $c; } return array("??","",""); */ } //else array("??","",""); } function GenerateUserCodeCalculator(){ $special_chars = array( array("","09","","horizontal tab"), array("","10","","line feed"), array("","32","","space"), array("","33","","exclamation mark"), array("quot","34","","double quotation mark"), array("","35","","number sign"), array("","36","","dollar sign"), array("","37","","percent sign"), array("amp","38","","ampersand"), array("","39","","apostrophe"), array("","40","","left parenthesis"), array("","41","","right parenthesis"), array("","42","","asterisk"), array("","43","","plus sign"), array("","44","","comma"), array("","45","","hyphen"), array("","46","","period"), array("frasl","47","","slash"), array("","58","","colon"), array("","59","","semicolon"), array("lt","60","","less-than sign"), array("","61","","equals sign"), array("gt","62","","greater-than sign"), array("","63","","question mark"), array("","64","","at sign"), array("","91","","left square bracket"), array("","92","","backslash"), array("","93","","right square bracket"), array("","94","","caret"), array("","95","","horizontal bar (underscore)"), array("","96","","grave accent"), array("","123","","left curly brace"), array("","124","","vertical bar"), array("","125","","right curly brace"), array("","126","","tilde"), array("","128","","euro"), array("","133","","reticencias"), array("","145","","aspa"), array("","146","","aspa"), array("","147","","aspas"), array("","148","","aspa"), array("","149","","ponto item"), array("ndash","150","","en dash"), array("mdash","151","","em dash"), array("nbsp","160","","nonbreaking space"), array("iexcl","161","","inverted exclamation"), array("cent","162","","cent sign"), array("pound","163","","pound sterling"), array("curren","164","","general currency sign"), array("yen","165","","yen sign"), array("brvbar; or &brkbar","166","","broken vertical bar"), array("sect","167","","section sign"), array("uml; or &die","168","","umlaut"), array("copy","169","","copyright"), array("ordf","170","","feminine ordinal"), array("laquo","171","","left angle quote"), array("not","172","","not sign"), array("shy","173","","soft hyphen"), array("reg","174","","registered trademark"), array("macr; or &hibar","175","","macron accent"), array("deg","176","","degree sign"), array("plusmn","177","","plus or minus"), array("sup2","178","","superscript two"), array("sup3","179","","superscript three"), array("acute","180","","acute accent"), array("micro","181","","micro sign"), array("para","182","","paragraph sign"), array("middot","183","","middle dot"), array("cedil","184","","cedilla"), array("sup1","185","","superscript one"), array("ordm","186","","masculine ordinal"), array("raquo","187","","right angle quote"), array("frac14","188","","one-fourth"), array("frac12","189","","one-half"), array("frac34","190","","three-fourths"), array("iquest","191","","inverted question mark"), array("Agrave","192","a","uppercase A, grave accent"), array("Aacute","193","a","uppercase A, acute accent"), array("Acirc","194","a","uppercase A, circumflex accent"), array("Atilde","195","a","uppercase A, tilde"), array("Auml","196","a","uppercase A, umlaut"), array("Aring","197","a","uppercase A, ring"), array("AElig","198","ae","uppercase AE"), array("Ccedil","199","c","uppercase C, cedilla"), array("Egrave","200","e","uppercase E, grave accent"), array("Eacute","201","e","uppercase E, acute accent"), array("Ecirc","202","e","uppercase E, circumflex accent"), array("Euml","203","e","uppercase E, umlaut"), array("Igrave","204","i","uppercase I, grave accent"), array("Iacute","205","i","uppercase I, acute accent"), array("Icirc","206","i","uppercase I, circumflex accent"), array("Iuml","207","i","uppercase I, umlaut"), array("ETH","208","eth","uppercase Eth, Icelandic"), array("Ntilde","209","n","uppercase N, tilde"), array("Ograve","210","o","uppercase O, grave accent"), array("Oacute","211","o","uppercase O, acute accent"), array("Ocirc","212","o","uppercase O, circumflex accent"), array("Otilde","213","o","uppercase O, tilde"), array("Ouml","214","o","uppercase O, umlaut"), array("times","215","x","multiplication sign"), array("Oslash","216","o","uppercase O, slash"), array("Ugrave","217","u","uppercase U, grave accent"), array("Uacute","218","u","uppercase U, acute accent"), array("Ucirc","219","u","uppercase U, circumflex accent"), array("Uuml","220","u","uppercase U, umlaut"), array("Yacute","221","y","uppercase Y, acute accent"), array("THORN","222","th","uppercase THORN, Icelandic"), array("szlig","223","ss","lowercase sharps, German"), array("agrave","224","a","lowercase a, grave accent"), array("aacute","225","a","lowercase a, acute accent"), array("acirc","226","a","lowercase a, circumflex accent"), array("atilde","227","a","lowercase a, tilde"), array("auml","228","a","lowercase a, umlaut"), array("aring","229","a","lowercase a, ring"), array("aelig","230","ae","lowercase ae"), array("ccedil","231","c","lowercase c, cedilla"), array("egrave","232","e","lowercase e, grave accent"), array("eacute","233","e","lowercase e, acute accent"), array("ecirc","234","e","lowercase e, circumflex accent"), array("euml","235","e","lowercase e, umlaut"), array("igrave","236","i","lowercase i, grave accent"), array("iacute","237","i","lowercase i, acute accent"), array("icirc","238","i","lowercase i, circumflex accent"), array("iuml","239","i","lowercase i, umlaut"), array("eth","240","eth","lowercase eth, Icelandic"), array("ntilde","241","n","lowercase n, tilde"), array("ograve","242","o","lowercase o, grave accent"), array("oacute","243","o","lowercase o, acute accent"), array("ocirc","244","o","lowercase o, circumflex accent"), array("otilde","245","o","lowercase o, tilde"), array("ouml","246","o","lowercase o, umlaut"), array("divide","247","","division sign"), array("oslash","248","o","lowercase o, slash"), array("ugrave","249","u","lowercase u, grave accent"), array("uacute","250","u","lowercase u, acute accent"), array("ucirc","251","u","lowercase u, circumflex accent"), array("uuml","252","u","lowercase u, umlaut"), array("yacute","253","y","lowercase y, acute accent"), array("thorn","254","th","lowercase thorn, Icelandic"), array("yuml","255","y","lowercase y, umlaut")); global $special_chars_search, $special_chars_replace; $special_chars_search = $special_chars; $special_chars_search = array_filter($special_chars_search,create_function('$elem', 'return $elem[1];')); array_walk($special_chars_search,create_function('&$elem', '$elem=chr($elem[1]);')); $special_chars_replace = $special_chars; $special_chars_replace = array_filter($special_chars_replace,create_function('$elem', 'return $elem[1];')); array_walk($special_chars_replace,create_function('&$elem', '$elem=$elem[2];')); } function WriteExcelFile($file,$assoc){ LoadClass("excel"); $export_file = "xlsfile://$file"; $fp = fopen($export_file, "wb"); if (!is_resource($fp)){ die("Cannot open $export_file"); } fwrite($fp, serialize($assoc)); fclose($fp); } function DownloadExcelFile($file){ LoadClass("excel"); $export_file = "xlsfile://$file"; header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT"); header ("Cache-Control: no-cache, must-revalidate"); header ("Pragma: no-cache"); header ("Content-type: application/x-msexcel"); header ("Content-Disposition: attachment; filename=\"" . basename($export_file) . "\"" ); header ("Content-Description: PHP/INTERBASE Generated Data" ); readfile($export_file); exit; } function GetFileExtension($fileName){ return substr($fileName, strrpos($fileName, '.') + 1); } function GetContentsFromCSVFile($tmp_file,$real_name){ $ext = GetFileExtension($real_name); if ($ext == "csv"){ return file_get_contents($tmp_file); }else{ //require_once 'reader.php'; LoadClass("excel"); // ExcelFile($filename, $encoding); $data = new Spreadsheet_Excel_Reader(); // Set output Encoding. $data->setOutputEncoding('CP1251'); $data->read($tmp_file); $contents = ''; for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) { for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) { $contents .= FixLines2String($data->sheets[0]['cells'][$i][$j]).";"; } $contents .= "\n"; } return $contents; } } function GetSignUnit($num){ if ($num < 0) return -1; else return 1; } function RequestPost($url,$params,$method = "post"){ Loadclass("rayhttp"); $http = new RayHttp(); if ($method=="post") $output = $http->post($url, $params ); else $output = $http->get($url, $params ); TestConnection(); return $output; } function RequestPost2($url,$data,$user=null,$pass=null){ LoadClass("HTTPPost"); if ($user){ $auth = array($user,$pass); } $post = new HTTPPost($url,$data,$auth); echo $post->post(); } function CutStr(&$str,$key,$len){ if (strlen($str)>$len) $cut = "..."; $str = (substr($str,0,$len).$cut); } function CutLines($str,$len){ $lines = split("\n",$str); array_walk($lines,"CutStr",$len); return join("\n",$lines); } function KillBlackListedRequests(){ global $_BLACK_LIST_HOST; if (in_array(_REMOTE_HOST,$_BLACK_LIST_HOST)) { CloseDBConnection(); exit(); } } function SetVariableInPost($var,$value){ if($var){ $_POST[$var]=$value; $_GET[$var]=$value; } } function SetGlobalVar($var,$value){ global $$var; $$var=$value; SetVariableInPost($var,$value); } function GetYesNoText($value){ if ($value) return _LANG_YES_TEXT; return _LANG_NO_TEXT; } function GetHostFromURL($url){ list($aux1,$aux2,$host,$uri) = split("/",$url); return $host; } function GetURIFromURL($url){ $parts = split("/",$url); return "/".join("/",array_splice($parts,3,count($parts))); } function IsZipFile($file){ return GetFileExtension($file)=="zip"; } function DecodeString($string){ $string = str_replace(array("\xE2\x80\x9C","\xE2\x80\x9D","\xE2\x80\x99"),array("\"","\"","'"),$string); if (mb_detect_encoding($string)=="UTF-8"){ $string = utf8_decode($string); } $search = array( " ", "¡", "¢", "£", "¤", "¥", "¦", "§", "¨", "©", "ª", "«", "¬", "­", "®", "¯", "°", "±", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "ƒ", "Α", "Β", "Γ", "Δ", "Ε", "Ζ", "Η", "Θ", "Ι", "Κ", "Λ", "Μ", "Ν", "Ξ", "Ο", "Π", "Ρ", "Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω", "α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", "λ", "μ", "ν", "ξ", "ο", "π", "ρ", "ς", "σ", "τ", "υ", "φ", "χ", "ψ", "ω", "ϑ", "ϒ", "ϖ", "•", "…", "′", "″", "‾", "⁄", "℘", "ℑ", "ℜ", "™", "ℵ", "←", "↑", "→", "↓", "↔", "↵", "⇐", "⇑", "⇒", "⇓", "⇔", "∀", "∂", "∃", "∅", "∇", "∈", "∉", "∋", "∏", "∑", "−", "∗", "√", "∝", "∞", "∠", "∧", "∨", "∩", "∪", "∫", "∴", "∼", "≅", "≈", "≠", "≡", "≤", "≥", "⊂", "⊃", "⊄", "⊆", "⊇", "⊕", "⊗", "⊥", "⋅", "⌈", "⌉", "⌊", "⌋", "〈", "〉", "◊", "♠", "♣", "♥", "♦", """, "&", "<", ">", "Œ", "œ", "Š", "š", "Ÿ", "ˆ", "˜", " ", " ", " ", "‌", "‍", "‎", "‏", "–", "—", "‘", "’", "‚", "“", "”", "„", "†", "‡", "‰", "‹", "›", "€", "̂", "́" ); $replace = array( " ", "¡", "¢", "£", "¤", "¥", "¦", "§", "¨", "©", "ª", "«", "¬", "­", "®", "¯", "°", "±", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "ƒ", "Α", "Β", "Γ", "Δ", "Ε", "Ζ", "Η", "Θ", "Ι", "Κ", "Λ", "Μ", "Ν", "Ξ", "Ο", "Π", "Ρ", "Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω", "α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", "λ", "μ", "ν", "ξ", "ο", "π", "ρ", "ς", "σ", "τ", "υ", "φ", "χ", "ψ", "ω", "&thetasy;", "ϒ", "ϖ", "•", "…", "′", "″", "‾", "⁄", "℘", "ℑ", "ℜ", "™", "ℵ", "←", "↑", "→", "↓", "↔", "↵", "⇐", "⇑", "⇒", "⇓", "⇔", "∀", "∂", "∃", "∅", "∇", "∈", "∉", "∋", "∏", "∑", "−", "∗", "√", "∝", "∞", "∠", "∧", "∨", "∩", "∪", "∫", "∴", "∼", "≅", "≈", "≠", "≡", "≤", "≥", "⊂", "⊃", "⊄", "⊆", "⊇", "⊕", "⊗", "⊥", "⋅", "⌈", "⌉", "⌊", "⌋", "⟨", "⟩", "◊", "♠", "♣", "♥", "♦", """, "&", "<", ">", "Œ", "œ", "Š", "š", "Ÿ", "ˆ", "˜", " ", " ", " ", "‌", "‍", "‎", "‏", "–", "—", "‘", "’", "‚", "“", "”", "„", "†", "‡", "‰", "‹", "›", "€", "", ""); //return str_replace(array("“","”","…","‹","‘","—","–","‰","′"), // array('"','"',"...","<","'","-","-","′"),$string); $string = str_replace($search,$replace,$string); return $string; } function html_entity_decode_utf8($string) { static $trans_tbl; // replace numeric entities $string = preg_replace('~&#x([0-9a-f]+);~ei', 'code2utf(hexdec("\\1"))', $string); $string = preg_replace('~&#([0-9]+);~e', 'code2utf(\\1)', $string); // replace literal entities if (!isset($trans_tbl)) { $trans_tbl = array(); foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key) $trans_tbl[$key] = utf8_encode($val); } return strtr($string, $trans_tbl); } function code2utf($number) { if ($number < 0) return FALSE; if ($number < 128) return chr($number); // Removing / Replacing Windows Illegals Characters if ($number < 160) { if ($number==128) $number=8364; elseif ($number==129) $number=160; // (Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160 elseif ($number==130) $number=8218; elseif ($number==131) $number=402; elseif ($number==132) $number=8222; elseif ($number==133) $number=8230; elseif ($number==134) $number=8224; elseif ($number==135) $number=8225; elseif ($number==136) $number=710; elseif ($number==137) $number=8240; elseif ($number==138) $number=352; elseif ($number==139) $number=8249; elseif ($number==140) $number=338; elseif ($number==141) $number=160; // (Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160 elseif ($number==142) $number=381; elseif ($number==143) $number=160; // (Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160 elseif ($number==144) $number=160; // (Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160 elseif ($number==145) $number=8216; elseif ($number==146) $number=8217; elseif ($number==147) $number=8220; elseif ($number==148) $number=8221; elseif ($number==149) $number=8226; elseif ($number==150) $number=8211; elseif ($number==151) $number=8212; elseif ($number==152) $number=732; elseif ($number==153) $number=8482; elseif ($number==154) $number=353; elseif ($number==155) $number=8250; elseif ($number==156) $number=339; elseif ($number==157) $number=160; // (Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160 elseif ($number==158) $number=382; elseif ($number==159) $number=376; } //if if ($number < 2048) return chr(($number >> 6) + 192) . chr(($number & 63) + 128); if ($number < 65536) return chr(($number >> 12) + 224) . chr((($number >> 6) & 63) + 128) . chr(($number & 63) + 128); if ($number < 2097152) return chr(($number >> 18) + 240) . chr((($number >> 12) & 63) + 128) . chr((($number >> 6) & 63) + 128) . chr(($number & 63) + 128); return FALSE; } //code2utf() function RemoveHTML($text,$tags=null){ if (is_array($tags)){ foreach ($tags as $tag){ $search = "/<".$tag."[^>]*>/"; $text = preg_replace($search,'',$text); $search = "/<\\/".$tag."\\s*>/"; $text = preg_replace($search,'',$text); } }else{ $search = "/<[a-zA-Z\/][^>]*>/"; $text = preg_replace($search,'',$text); } return $text; } function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } function StartTimer(){ global $mytimer; $mytimer = microtime_float(); } function DisplayTimer($text){ global $mytimer; echo "$text ". (microtime_float() - $mytimer)."
"; } function GetTimerInterval(){ global $mytimer; return round(microtime_float() - $mytimer,3); } function IsOdd($num){ return $i&1; } function LogChangeInDB($object,$objectid,$subtask=null){ LoadClass("date_time"); if (!$userid= $_SESSION["userid_session"]) $userid =-1; $date = new _DateTime(); $date->SetDateTimeNow(); $date = $date->GetDateTimeForDB(); $action = getVarPassed("action",_TYPE_ACTION); if ($task = getVarPassed("task",_TYPE_ACTION)) $action .=".$task"; if ($subtask) $action .=".$subtask"; $SQL_query = "INSERT INTO log_actions (object,objectid,userid,date,action) VALUES ('$object',$objectid,$userid,$date,'$action')"; ExecuteSQLQuery($SQL_query); } function Redirect2SystemMessage($msg,$params=null){ if ($params){ foreach ($params as $param =>$value){ $args .="$param=$value&"; } } Redirect2("system_messages.php?message=".$msg."&$args"); } function GetSQLFromFilters($filters=null){ if (!empty($filters)){ if(!is_array($filters)){ $filters = array($filters); } foreach ($filters as $filter){ $SQL_tables .=$filter->GetQueryTables(); $SQL_filter .= $filter->GetQueryCondition(); } } return array($SQL_tables,$SQL_filter); } function ValidateDevAccess(){ global $via; $file_basename = basename ($_SERVER["PHP_SELF"]); $dev_scripts_ok = array("start.php","index.php","login.php","ajax.php"); $wild_card = getVarPassed("devwc",_TYPE_CHAR); $wildcard_ok = $wild_card && ($wild_card ==_DEV_WILDCARD); if (_DEV_SITE=="on" && !in_array($file_basename,$dev_scripts_ok) && $via !=_SUPER && !$wildcard_ok){ //if (!Autenticate(_SUPER,null,null,false)){ $vars = $_POST + $_GET; foreach($vars as $name =>$value){ $query_string .= "$name=" . urlencode($value) . '&'; } header("Location: http://www.sportoasis.pt/oasis/".$file_basename."?$query_string"); //} } } function SetTransactionFees($country_code_zone,$total_fee, $object){ global $_ONLINE_PAYMENTS_LIMIT; $to_pay = $total_fee; list($limit_total, $ratio_min, $ratio_max,$fixed_fee) = $_ONLINE_PAYMENTS_LIMIT[$country_code_zone]; $total_fee = round((float($to_pay)*float($ratio_max)) + float($fixed_fee),2); $ratio_current = float($ratio_max); while( float($total_fee) > float($limit_total) && float($ratio_current) > float($ratio_min)){ $ratio_current =float ($ratio_current-0.005); $total_fee = round(($to_pay*$ratio_current) + float($fixed_fee),2); } $object->transaction_fee = $total_fee; $object->transaction_fee_ratio = $ratio_current; $object->transaction_fee_fixed = $fixed_fee; } function SplitNames($name){ if ($name){ $names = split(" ",$name); $lname = $names[count($names)-1]; unset($names[count($names)-1]); $fname = join(" ",$names); } return array($fname,$lname); } function AddFeesMethods2List(&$methods_list,$classprefix=null){ global $eventid,$objSuper; LoadClass("entry_extra_promotion"); foreach (array("club","classevent",$classprefix."entry",$classprefix."entryevent") as $object){ if (!$methods_list[$object]) $methods_list[$object]=array(); } array_push($methods_list['club'], array("LoadFeesInfoFromDB", array($eventid))); array_push($methods_list['classevent'], array("LoadFeesInfoFromDB", array($eventid))); array_push($methods_list[$classprefix."entry"], array("LoadFeesInfoFromDB")); array_unshift($methods_list[$classprefix.'entryevent'], array("LoadLicenseInfoFromDB")); array_push($methods_list[$classprefix.'entryevent'], array("LoadExtrasPromotionsInfoFromDB")); array_push($methods_list[$classprefix.'entryevent'], array("CalculateInsuranceFee")); array_push($methods_list[$classprefix.'entryevent'], array("LoadFeesInfoFromDB")); InsertGlobalInXML($objSuper,"entry_fee_rented_si",_ENTRY_FEE_RENTED_SI); InsertGlobalInXML($objSuper,"license_state_yes",_LICENSE_STATE_YES); } function GetGeoInfoFromIP($ip){ LoadClass("geoip"); // uncomment for Shared Memory support // geoip_load_shared_mem("/usr/local/share/GeoIP/GeoIPCity.dat"); // $gi = geoip_open("/usr/local/share/GeoIP/GeoIPCity.dat",GEOIP_SHARED_MEMORY); $gi = geoip_open(_ROOT_SITE_LOCAL."geoip/GeoLiteCity.dat",GEOIP_STANDARD); $record = geoip_record_by_addr($gi,$ip); $country = $record->country_name; $country_code = $record->country_code3; $region = $GEOIP_REGION_NAME[$record->country_code][$record->region]; $region_code = $record->region; $postal_code = $record->postal_code; $latitude = $record->latitude; $longitude = $record->longitude; $city=$record->city; geoip_close($gi); return array($country,$country_code,$region,$region_code,$postal_code,$latitude,$longitude,$city); } function CreateTelephone($object,$number=1){ if ($object){ $id = $object->id; $ownerid = $object->$id; $owner_type = $object->GetClassName(); return new Telephone($owner_type,$ownerid,$number); } } function LoadTelephonesInfoFromDB($object){ if ($object){ $id = $object->id; $ownerid = $object->$id; $owner_type = $object->GetClassName(); $SQL_query="SELECT * FROM telephones WHERE (ownerid='$ownerid' AND owner_type='$owner_type') ORDER by number"; $objRSTel_query=ExecuteSQLQuery($SQL_query); while($objRSTel = mysql_fetch_array($objRSTel_query, MYSQL_ASSOC)){ $telephone = new Telephone(); $telephone->LoadMainInfoFromDB($objRSTel); $object->AddTelephone($telephone); } } } function LoadAddressInfoFromDB($object){ if ($object){ $id = $object->id; $ownerid = $object->$id; $owner_type = $object->GetClassName(); $SQL_query="SELECT * FROM addresses WHERE (ownerid='$ownerid' AND owner_type='$owner_type') ORDER by number"; $objRSUser_query=ExecuteSQLQuery($SQL_query); while($objRSUser = mysql_fetch_array($objRSUser_query, MYSQL_ASSOC)){ $object->address = $object->CreateAddress(); $object->address->LoadMainInfoFromDB($objRSUser); } } } function SetOwnerIDInAddress($object){ if ($object && $object->address){ $id = $object->id; $ownerid = $object->$id; $owner_type = $object->GetClassName(); $object->address->SetOwnerID($ownerid); $object->address->SetOwnerType($owner_type); } } function SetOwnerIDInTelephones($object){ if ($object && ($telephones = $object->telephones)){ $id = $object->id; $ownerid = $object->$id; $owner_type = $object->GetClassName(); foreach ($telephones as $tel){ $tel->SetOwnerID($ownerid); $tel->SetOwnerType($owner_type); } } } function TelephonesInfo2DB($object){ if ($object && ($telephones = $object->telephones)){ foreach ($telephones as $tel){ $tel->MainInfo2DB(); } $id = $object->id; $ownerid = $object->$id; $owner_type = $object->GetClassName(); $total_tel = count($telephones); $SQL_query="DELETE FROM telephones WHERE (ownerid='$ownerid' AND owner_type='$owner_type' AND number>$total_tel)"; ExecuteSQLQuery($SQL_query); } } function DeleteTelephonesFromDB($object){ $object->telephones = array(); TelephonesInfo2DB($object); } function DeleteAddressFromDB($object,$number=1){ if ($object && $object->address){ $object->address->DeleteInfoFromDB(); } } function LoadTelephonesInfoFromForm($object,$prefix=null){ if ($object){ $total = getVarPassed($prefix."total_telephones",_TYPE_INTEGER); $object->telephones = array(); $numtel = 1; for($i = 1; $i <= $total; $i++){ if (getVarPassed($prefix."telephone_digits_$i",_TYPE_TELEPHONE)){ $telephone = new Telephone($object->GetClassName(),$object->GetID(),$numtel++); $telephone->LoadMainInfoFromForm($prefix); $object->AddTelephone($telephone); //array_push($telephones,$telephone); } } } } function FullFillTelephones($object, $num){ if (intval($num)){ $id = $object->id; $ownerid = $object->$id; for($i = count($object->telephones)+1; $i<=$num;$i++){ $object->AddTelephone(new Telephone($object->GetClassName(),$ownerid,$i)); } } } function FullFillTelephones2XML($xml,$object, $num){ if (intval($num)){ $id = $object->id; $ownerid = $object->$id; for($i = count($object->telephones)+1; $i<=$num;$i++){ $tel = new Telephone($object->GetClassName(),$ownerid,$i); $xmlT = AddElementInXML($xml,"telephone"); $tel->MainInfo2XML($xmlT); } } } function CreateIndexFromList($list,$id){ $index = array(); foreach ($list as $elem){ $index[$elem->$id] = $elem; } return $index; } function SplitString2List($list){ return array_filter(explode(" ",str_replace(array(",","\t","\r\n","\n",";"), " ",$list))); } function CalculateViaOrg($is_event_admin=null,$user=null,$eventid=null,$passed_via_org=null){ global $via; if ($passed_via_org) return $passed_via_org; if ($user && $eventid){ $is_event_admin = $user->IsAdminOfEvent($eventid); } if ($is_event_admin || $via ==_SUPER){ return _ENTRIES_STATE_VALIDATED; }elseif ($via > _NORMAL){ return _ENTRIES_STATE_AWAITING_ORGANIZATION; }else { return _ENTRIES_STATE_AWAITING_CLUB; } } function GetFieldFromDBQueryResult($RecSet_query,$field){ $results = array(); if ($RecSet_query && $field){ while($recset = mysql_fetch_array($RecSet_query, MYSQL_ASSOC)){ array_push($results,$recset[$field]); } return $results; } } function GetSessionRankingStates(){ global $via; if ($via != _SUPER) return array(_RANKING_STATUS_ACTIVE); } function byte_convert($bytes) { $symbol = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); $exp = 0; $converted_value = 0; if( $bytes > 0 ) { $exp = floor( log($bytes)/log(1024) ); $converted_value = ( $bytes/pow(1024,floor($exp)) ); } return sprintf( '%.2f '.$symbol[$exp], $converted_value ); } function LogEntriesChange2DB($action,$table,$cols,$logid,$userid,$user_type,$table_keys){ $date = new _DateTime(_DATE_TIME_NOW); if($logid){ $logid .=","; $logid_col ="logid,"; } foreach ($table_keys as $key=>$val){ $sql_key .= $key."='$val' AND "; } $sql_key = substr($sql_key,0,-4); $SQL_query="INSERT log_$table ($logid_col log_datetime, log_userid,log_user_type, log_action, ". join($cols,",").")". " SELECT $logid '".$date->GetStringDateTime()."', '$userid', '$user_type','$action',". join($cols,","). " FROM $table ". " WHERE $sql_key"; ExecuteSQLQuery($SQL_query); return mysql_insert_id(); } function DBStats2XML($xml,$DB=null){ global $_DB_SETTINGS; if (!$myDB){ $myDB = _DB_OASIS; } AddElementInXML($xml,"total_sql_queries",$_DB_SETTINGS[$myDB][_DB_SETTINGS_TOTAL_QUERIES]); AddElementInXML($xml,"time_sql_queries",number_format($_DB_SETTINGS[$myDB][_DB_SETTINGS_TOTAL_TIME],3)); if ($_DB_SETTINGS[$myDB][_DB_SETTINGS_QUERIES]){ $xmlSQL = AddElementInXML($xml,"sql_queries",number_format($_DB_SETTINGS[$myDB][_DB_SETTINGS_TOTAL_TIME],3)); foreach ($_DB_SETTINGS[$myDB][_DB_SETTINGS_QUERIES] as $query){ $xmlQuery = AddElementInXML($xmlSQL,"query"); AddElementInXML($xmlQuery,"sql", $query[0]); AddElementInXML($xmlQuery,"time", $query[1]); } } } function SaveFileFromURL($url,$dest){ if ($contents = file_get_contents($url)){ file_put_contents($dest,$contents); } } function TempFile2Zip($path_new_file,$path_new_file_cache,$tmp_file,$new_contents){ if (is_array($new_contents))$new_contents=join($new_contents); file_put_contents($path_new_file_cache,$new_contents); $archive = new PclZip($path_new_file); $v_list = $archive->create($path_new_file_cache,PCLZIP_OPT_REMOVE_ALL_PATH); if ($v_list == 0) { die("Error : ".$archive->errorInfo(true)); } if (file_exists($tmp_file)) unlink($tmp_file); } function ExtractZipFile($file,$tmp_dir){ $archive = new PclZip($file); $list = $archive->extract($tmp_dir); $tmp_file = $tmp_dir.$list[0]["stored_filename"]; return $tmp_file; } function CalculateHolidays($years){ $days = array(); if (is_array($years)){ foreach ($years as $year){ if(_COUNTRY_CODE_DEFAULT=="PT"){ array_push($days,"$year-01-01"); array_push($days,"$year-04-25"); array_push($days,"$year-05-01"); array_push($days,"$year-06-10"); array_push($days,"$year-08-15"); array_push($days,"$year-10-05"); array_push($days,"$year-11-01"); array_push($days,"$year-12-01"); array_push($days,"$year-12-08"); array_push($days,"$year-12-25"); $easter = easter_date($year); array_push($days,date("d-m-Y",$easter)); array_push($days,date("d-m-Y",strtotime("-47 day",$easter))); // carneval array_push($days,date("d-m-Y",strtotime("-2 day",$easter))); // good friday array_push($days,date("d-m-Y",strtotime("60 day",$easter))); // Corpus Christi (feast) } } } return $days; } function CalculateTotalWeeksInYear($years){ $count = array(); if (!is_array($years)) $years = array($years); foreach ($years as $year){ if ($year) $count[$year]= date("W",mktime(23,59,59,12,31,$year)); } return $count; } function CalculateUniqueYears($start_date_obj,$end_date_obj){ if ($start_date_obj && $end_date_obj){ $start_year = $start_date_obj->GetYear(); $end_year = $end_date_obj->GetYear(); $years = array(); for($year = $start_year; $year <= $end_year;$year++){ array_push($years,$year); } return $years; } } function GetContactEmail($id=null,$email_only=false){ global $_CONTACTS_EMAIL; if (!$_CONTACTS_EMAIL[$id]) $id = _CONTACT_EMAIL_GENERAL; $contact = $_CONTACTS_EMAIL[$id]; if ($email_only) return $contact[0]; else return $contact; } function CreateContactEmail($email,$str=null){ global $_CONTACTS_EMAIL; if ($_CONTACTS_EMAIL[$email]) $email = $_CONTACTS_EMAIL[$email][0]; if ($str){ $email = "\"$str\" <$email>"; } return $email; } function ApplyVariablesToText($text,$vars){ $i = 1; if (!is_array($vars)) $vars = array($vars); foreach ($vars as $var){ $text = str_replace("%var$i%",$var,$text); $i++; } return $text; } function GetDBInsertedID(){ return mysql_insert_id(); } function LoadSubmitInfo($obj){ $obj->client_ip = $_SERVER["REMOTE_ADDR"]; $obj->client_host = getremote(); $obj->client_browser = $_SERVER['HTTP_USER_AGENT']; if (!$obj->client_referer = $_SESSION['entrance_referer']) $obj->client_referer = $_SERVER['HTTP_REFERER']; list ($obj->country,$obj->country_code ,$obj->region,$obj->region_code,$obj->postal_code, $obj->latitude ,$obj->longitude, $obj->city) = GetGeoInfoFromIP($obj->client_ip); $obj->client_place = $obj->city . " (". $obj->country_code . ")"; $obj->registration_date = new _DateTime(_DATE_TIME_NOW); } function full_url(){ $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $sp = strtolower($_SERVER["SERVER_PROTOCOL"]); $protocol = substr($sp, 0, strpos($sp, "/")) . $s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI']; } function LoadPermlink(){ global $perm_links, $LANGUAGES_SHORT; $perm_link = $_SERVER["REQUEST_URI"]; $perm_link = str_replace("\\","/",$perm_link); if (strlen(_ROOT_SITE_URI) > 1) $perm_link = str_replace(_ROOT_SITE_URI, "", $perm_link); $perm_links = array_values(array_filter(explode("/",$perm_link))); //$perm_link=reset($perm_links); if($perm_links[0] && ($lang = $LANGUAGES_SHORT[$perm_links[0]])){ SetVariableInPost("lang",$lang); array_shift($perm_links); $perm_links = array_values($perm_links); } foreach ($perm_links as $i => $pl){ $var_name = "arg$i"; global $$var_name; $$var_name = $pl; SetVariableInPost("arg$i",$pl); } /* if($lang = $LANGUAGES_SHORT[$arg0]){ SetVariableInPost("lang",$lang); } */ } function PageLinks2XML($xml){ global $_PAGES_INDEX; $xmlPermlinks = InsertGlobalInXML($xml,"links"); foreach ($_PAGES_INDEX as $index => $page){ $xmlPage = AddElementInXML($xmlPermlinks,$index,$page[1]); } } function GetPermLink($index){ global $_PAGES_INDEX; return $_PAGES_INDEX[$index][1]; } function AddLocationCities2PagesIndex(){ global $_LOCATIONS_CITIES, $_PAGES_INDEX; if (!empty($_LOCATIONS_CITIES)){ foreach ($_LOCATIONS_CITIES["cities"][1] as $code=>$city){ $_PAGES_INDEX["city_$code"]=array("start.php?query=".$city."&city=$code",$code); } } } function IsCityCode($code){ global $_LOCATIONS_CITIES; return $_LOCATIONS_CITIES["cities"][1][$code]; } function GetCityName($code){ global $_LOCATIONS_CITIES; return $_LOCATIONS_CITIES["cities"][1][$code]; } function Jobs2XML($xml,$cols,$lines=null,$suffix=null){ global $_LOCATIONS_CITIES, $_PAGES_INDEX; $icol = 1; $iline = 1; $xmlJobs = AddElementInXML($xml,"jobs$suffix"); $ijob = 1; $jobgrs = array(); foreach ($_LOCATIONS_CITIES as $aid => $area){ $area_name = $area[0]; $newjobs = array(); $numpercol = floor(count($area[1])/$cols); $k=1; $coln=1; $newjobs[$coln]=array(); foreach ($area[1] as $activid =>$activ){ if ($k++> $numpercol){ $k=2; $coln++; $newjobs[$coln]=array(); } $newjobs[$coln]= array_merge($newjobs[$coln],array($activid=>$activ)); } $jobgrs = array_merge($jobgrs,array($aid=>array($area_name,$newjobs))); if ($lines){ $xmlCol = AddElementInXML($xmlJobs,"col"); SetAttributeInXML($xmlCol,"aid",$aid); $iline=1; $xmlLine = AddElementInXML($xmlCol,"line",$area_name); SetAttributeInXML($xmlLine,"type","title"); SetAttributeInXML($xmlLine,"numcols",ceil(count($area[1])/$lines)); SetAttributeInXML($xmlLine,"id",$aid); SetAttributeInXML($xmlLine,"num",$ijob++); SetAttributeInXML($xmlLine,"aid",$aid); //$iline+=1; foreach ($area[1] as $activid =>$activ){ $activ_name = $activ[0]; $xmlLine = AddElementInXML($xmlCol,"line",$activ); SetAttributeInXML($xmlLine,"id",$activid); SetAttributeInXML($xmlLine,"url",utf8_encode($_PAGES_INDEX["city_".$activid][1])); SetAttributeInXML($xmlLine,"num",$ijob++); if (++$iline>$lines){ $xmlCol = AddElementInXML($xmlJobs,"col"); SetAttributeInXML($xmlCol,"aid",$aid); //$xmlLine = AddElementInXML($xmlCol,"line"); $iline=1; } } } } $xmlJobGrs = AddElementInXML($xml,"jobsgr$suffix"); $ijob=0; foreach ($jobgrs as $areaid=>$jobgr){ $xmlGr = AddElementInXML($xmlJobGrs,"group"); AddElementInXML($xmlGr,"name",$jobgr[0]); AddElementInXML($xmlGr,"numcols",$cols); foreach ($jobgr[1] as $grcols){ $xmlCol = AddElementInXML($xmlGr,"col"); foreach ($grcols as $activid =>$activ){ $xmlLine = AddElementInXML($xmlCol,"line",$activ); SetAttributeInXML($xmlLine,"id",$activid); SetAttributeInXML($xmlLine,"url",utf8_encode($_PAGES_INDEX["city_".$activid][1])); SetAttributeInXML($xmlLine,"num",++$ijob); } } } AddElementInXML($xml, "total_jobs",$ijob); } function GetHomeRootDomain(){ $dom_parts = explode(".",$_SERVER['SERVER_NAME']); if(count($dom_parts) > 2){ array_shift($dom_parts); } return join(".",$dom_parts); } function StandardizeText($text,$spacer="_"){ global $special_chars_search,$special_chars_replace, $tags; require_once(_ROOT_SITE_LOCAL. "special_chars.php"); $text = str_replace(chr(10)," ",$text); $text = strtolower($text); $text = str_replace($special_chars_search,$special_chars_replace,$text); $text = array_filter(explode(" ",$text)); return join($spacer,$text); }