telefonnummer eller lämna fältet tomt."); if($Req) $Msg = _("Ange ett giltigt telefonnummer."); try { $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance(); $No = $phoneUtil->parse($Phone); if(true === $phoneUtil->isValidNumber($No)){ return preg_replace_callback( '/\+([\d]+)\s([\d]+)\s([\d\s]+)/', function($m) { return sprintf('%s-%s-%s', $m[1], $m[2], preg_replace('/[^0-9]+/', '', $m[3])); }, $phoneUtil->format($No, \libphonenumber\PhoneNumberFormat::INTERNATIONAL) ); } throw new KOCommonException($Msg, 0); return false; } catch (\libphonenumber\NumberParseException $e) { throw new KOCommonException($Msg, 0); return false; } } /* validate email -- ------------------------------*/ public static function IsValidEmail($Email = ""){ global $__AdmPath; if(false === (bool)Swift_Validate::email($Email)){ throw new KOCommonException(_("E-postadressen är ogiltig."), 0); } return true; } /* email missing -- ------------------------------*/ public static function IsEmailMissing($Email = ""){ if(strlen($Email) === 0){ throw new KOCommonException(_("E-postadress saknas."), 0); } return true; } /* currency field -- ------------------------------*/ public static function CurrencyField($Params = ""){ global $__CURRENCY; $Curr = $__CURRENCY[SYSTEM_CURRENCY]; $Item = sprintf('
%s
', $Curr['Symbol']); if($Curr['SymbolBefore'] !== false) $Item = sprintf('
%s
', $Curr['Symbol']); return sprintf($Item, $Params); } /* activity state array -- ------------------------------*/ static function ArrActivityState(){ return array( 1 => _("Öppen för bokning"), 2 => _("Stängd"), 3 => _("Öppen med förtur"), 4 => _("Öppen med prova-på"), ); } static function SetGroupStatus($S){ $Status = self::ArrActivityState(); return (isset($Status[$S]) ? $Status[$S] : 'n/a'); } /* gender array -- ------------------------------*/ static function Gender(){ return array( 1 => _("Man"), 2 => _("Kvinna"), ); } /* yes/no array -- ------------------------------*/ static function ArrYesNo(){ return array( 1 => _("Nej"), 2 => _("Ja"), ); } /* weekdays array -- ------------------------------*/ static function Weekdays(){ return array( 1 => _("måndag"), 2 => _("tisdag"), 3 => _("onsdag"), 4 => _("torsdag"), 5 => _("fredag"), 6 => _("lördag"), 0 => _("söndag"), ); } /* weekdays short / sv array -- ------------------------------*/ static function WeekdaysSv(){ return array( 1 => _("mån"), 2 => _("tis"), 3 => _("ons"), 4 => _("tor"), 5 => _("fre"), 6 => _("lör"), 7 => _("sön"), ); } /* weekdays short array -- ------------------------------*/ static function WeekdaysAbbr(){ return array( _('sön'), _('mån'), _('tis'), _('ons'), _('tor'), _('fre'), _('lör'), ); } /* months array -- ------------------------------*/ static function Monthnames(){ return array( _('januari'), _('februari'), _('mars'), _('april'), _('maj'), _('juni'), _('juli'), _('augusti'), _('september'), _('oktober'), _('november'), _('december'), ); } /* occasion type array -- ------------------------------*/ static function OccasionTypes(){ return array( 1 => _("Träning"), 11 => _("Landträning"), 2 => _("Match/Tävling/Cup"), 21 => _("Hemmamatch"), 22 => _("Bortamatch"), 3 => _("Möte"), 4 => _("Utbildning"), 5 => _("Läger"), 6 => _("Övrigt"), 7 => _("Årsmöte"), 8 => _("Styrelsemöte"), 9 => _("Kommittémöte"), ); } /* invitations -- ------------------------------*/ static function invitation_types(){ return [ 1 => _('Alla obesvarade'), 2 => _('Alla'), 3 => _('Markerade') ]; } static function invitation_recipients(){ return [ 0 => _('Manuellt urval'), 1 => _('Alla'), 2 => _('Endast deltagare (och målsman)'), 3 => _('Endast ledare') ]; } public static function EmailTemplates(){ return [ 'ACCOUNT_ACTIVATION' => _('Kontoaktivering/glömt lösenord'), 'ACCOUNT_CREATE' => _('Välkomstmail/nytt konto'), 'ATTENDANCE_REMINDER' => _('Aktivitetstillfälle, orapporterad'), 'BLANK' => _('Tom mall'), 'COMPETITION_NOTIFY' => _('Tävlingsanmälan, bekräftelse'), 'COMPETITION_NOTIFY_CANCEL' => _('Tävlingsanmälan, avanmälan'), 'CONTACT_US' => _('Kontakta oss'), 'EMAIL_FOOTER' => _('E-postmall, fot'), 'EMAIL_HEADER' => _('E-postmall, huvud'), 'INVOICE_CREATED' => _('Fakturaavisering'), 'INVOICE_CREATED_CUSTOMFEE' => _('Fakturaavisering, enskild avgift'), 'INVOICE_PAYMENT_REGISTER' => _('Betalningsavisering'), 'MEMBERSHIP_INVITATION' => _('Inbjudan, Medlemskap'), 'INVITATION_REMOVED' => _('Inbjudan, Borttagning'), 'NOTIFY_CHANGED' => _('Bokning, ändrad'), 'NOTIFY_CREATED' => _('Bokning, skapad'), 'GROUP_INVITATION' => _('Inbjudan, Bokning'), 'OCCASION_INVITATION' => _('Aktivitetstillfälle, kallelse'), 'OCCASION_REMINDER' => _('Aktivitetstillfälle, kommande'), 'ORDER_CREATED' => _('Order, skapad'), 'ORDER_STATUS_CHANGED' => _('Order, ändrad'), // 'USER_ACTIVATION' => _('Kontoaktivering, användare'), ]; } /* datum -- ----------*/ public static function DateRangeDT($start, $end){ try { $Ds = new DateTime($start); $De = new DateTime($end); $Dt = false; /* inte samma -- ----------*/ if($Ds != $De){ /* samma dag -- ----------*/ if($Ds->format('Ymd') === $De->format('Ymd')){ $Dt = [ 'label' => _('Datum/tid'), 'date' => $Ds->format('l j M Y'), 'time' => sprintf('%s - %s', $Ds->format('H:i'), $De->format('H:i')) ]; if($Ds->format('Hi') == '0000'){ $Dt['time'] = null; }elseif($De->format('Hi') == '0000'){ $Dt['time'] = $Ds->format('H:i'); } /* inte samma dag -- ----------*/ }elseif($Ds->format('Ymd') !== $De->format('Ymd')){ $STime = $Ds->format('H:i'); if($Ds->format('Hi') == '0000') $STime = null; $ETime = $De->format('H:i'); if($De->format('Hi') == '0000') $ETime = null; $Dt = [ [ 'label' => _('Startar'), 'date' => $Ds->format('l j M Y'), 'time' => $STime ], [ 'label' => _('Slutar'), 'date' => $De->format('l j M Y'), 'time' => $ETime ], ]; /* $Dt['date'] = sprintf('%s - %s', $Ds->format('l j M'), $De->format('l j M Y')); $Dt['time'] = sprintf('%s - %s', $Ds->format('H:i'), $De->format('H:i')); */ /* samma månad -- ----------*/ }elseif($Ds->format('Ym') === $De->format('Ym')){ } }elseif($Ds == $De){ $Dt = [ 'label' => _('Datum/tid'), 'date' => $Ds->format('l j M Y'), 'time' => $Ds->format('H:i') ]; if($Ds->format('Hi') == '0000'){ $Dt['time'] = null; } } return $Dt; } catch(Exception $e){ return false; } } public static function DateRange($start, $end){ try { $Ds = strtotime($start); $De = strtotime($end); $Dt = false; /* inte samma -- ----------*/ if($Ds != $De){ /* samma dag -- ----------*/ if(date('Ymd', $Ds) === date('Ymd', $De)){ $Dt = [ 'label' => _('Datum/tid'), 'date' => strftime(DATE_DAY_MONTH_YEAR, $Ds), 'time' => sprintf('%s - %s', strftime(DATE_HOUR_MINUTE, $Ds), strftime(DATE_HOUR_MINUTE, $De)) ]; if(date('Hi', $Ds) === '0000'){ $Dt['time'] = null; }elseif(date('Hi', $De) === '0000'){ $Dt['time'] = strftime(DATE_HOUR_MINUTE, $Ds); } /* inte samma dag -- ----------*/ }elseif(date('Ymd', $Ds) !== date('Ymd', $De)){ $STime = strftime(DATE_HOUR_MINUTE, $Ds); if(date('Hi', $Ds) === '0000') $STime = null; $ETime = strftime(DATE_HOUR_MINUTE, $De); if(date('Hi', $De) === '0000') $ETime = null; $Dt = [ [ 'label' => _('Startar'), 'date' => strftime(DATE_DAY_MONTH_YEAR, $Ds), 'time' => $STime ], [ 'label' => _('Slutar'), 'date' => strftime(DATE_DAY_MONTH_YEAR, $De), 'time' => $ETime ], ]; /* samma månad -- ----------*/ // }elseif($Ds->format('Ym') === $De->format('Ym')){ } }elseif($Ds == $De){ $Dt = [ 'label' => _('Datum/tid'), 'date' => strftime(DATE_DAY_MONTH_YEAR, $Ds), 'time' => strftime(DATE_HOUR_MINUTE, $Ds) ]; if(date('Hi', $Ds) == '0000'){ $Dt['time'] = null; } } return $Dt; } catch(Exception $e){ return false; } } static function SetOccasionType($T){ $Types = self::OccasionTypes(); return (isset($Types[$T]) ? $Types[$T] : 'n/a'); } /* occasion status array -- ------------------------------*/ static function OccasionStatus(){ return array( 0 => _("Ej rapporterad"), 1 => _("Rapporterad"), 2 => _("Låst"), ); } static function SetOccasionStatus($S){ $Status = self::OccasionStatus(); return (isset($Status[$S]) ? $Status[$S] : 'n/a'); } /* invoice status array -- ------------------------------*/ static function InvoiceStatus(){ return array( 1 => _("Skapad"), 2 => _("Betald"), 3 => _("Kvittad"), ); } static function SetInvoiceStatus($S){ $Status = self::InvoiceStatus(); return (isset($Status[$S]) ? $Status[$S] : 'n/a'); } /* section settings -- ------------------------------*/ static function SectionSettings($Id){ $dbh = Database::getInstance(); $query = " SELECT `ID`, `Section`, `Name`, `section_id`, `section_name`, `section_autotag`, `IOLok`, `sport`, `section_props` FROM `content_menu` INNER JOIN `school_section` ON `Section` = `section_id` WHERE `ID` = :SectionId LIMIT 1 "; $pst = $dbh->prepare($query); $pst->bindParam(":SectionId", $Id, PDO::PARAM_INT); $pst->execute(); if($pst->rowCount() !== 0){ $res = $pst->fetch(PDO::FETCH_ASSOC); $Props = array(); if(!is_null($res['section_props']) && false !== $P = unserialize($res['section_props'])) $Props = $P; return array( "Id" => (int)$res['ID'], "Section" => (int)$res['section_id'], "Name" => $res['Name'], "Settings" => array( "Id" => (int)$res['section_id'], "Name" => $res['section_name'], "Slug" => post_slug($res['section_name']), "Tag" => $res['section_autotag'], "IOLok" => (int)$res['IOLok'], "Sport" => (int)$res['sport'], "Props" => $Props, ) ); } $pst = null; return false; } static function SectionsList(){ $dbh = Database::getInstance(); $query = " SELECT `ID`, `Section`, `Name`, `Order`, `section_desc` FROM `content_menu` INNER JOIN `school_section` ON `Section` = `section_id` ORDER BY `Order`, `Name` "; $pst = $dbh->prepare($query); $pst->execute(); if($pst->rowCount() === 0) return false; $i = 0; $Sections = array(); while($S = $pst->fetch(PDO::FETCH_ASSOC)){ $Sections[$i] = array( "Id" => (int)$S['ID'], "Name" => $S['Name'], "Desc" => null, ); if(!is_null($S['section_desc'])) $Sections[$i]['Desc'] = $S['section_desc']; $i++; } return $Sections; } /* payment types -- ------------------------------*/ static function PaymentNames(){ return array( 707 => _("Pappersfaktura"), 708 => _("E-postfaktura"), 1 => _("Konto/kreditkort"), 709 => _("Swish"), ); } public static function OnlinePaymentTypes(){ $dbh = Database::getInstance(); $Data = array(); $query = " SELECT COUNT(`pm_id`) FROM `system_payment_method` WHERE `pm_parent` <> 0 AND `pm_default` = 2 ORDER BY `pm_parent` "; $pst = $dbh->prepare($query); $pst->execute(); return ((int)$pst->fetchColumn() !== 0); /* while($res = $pst->fetch(PDO::FETCH_ASSOC)){ $Data[] = (int)$res['pm_id']; } */ $pst = null; return $Data; /* return array( 1, // Visa 2, // MasterCard 3, // American Express 4, // Diners Club 800, // Eurocard 801, // Maestro ); */ } /* betalsätt -- ------------------*/ public static function PaymentTypes($Selected = 0){ global $__payment_settings; $Type = array(); $PaymentGroups = array( 1 => _("Kontokort/Swish"), 2 => _("Bankbetalning"), 0 => _("Övriga"), ); $PaymentNames = KOCommon::PaymentNames(); $__NOTIFIES_VAT = (int)config("NOTIFIES_VAT"); $dbh = Database::getInstance(); $query = " SELECT `pm_id`, `pm_parent`, `pm_name`, `pm_default`, `pm_fee`, `pm_custom` FROM `system_payment_method` WHERE `pm_default` = 2 ORDER BY CASE WHEN `pm_parent` = 0 THEN 3 END ASC, `pm_parent`, `pm_order` "; $query = " SELECT `pm_id`, `pm_parent`, `pm_name`, `pm_fee` FROM `system_payment_method` WHERE `pm_default` = 2 "; if(isset($__payment_settings['provider'])){ $query .= " AND `pm_parent` = 0 "; } /* $query .= " ORDER BY CASE WHEN `pm_id` = 709 THEN 1 WHEN `pm_id` = 1 THEN 2 END ASC, `pm_order` "; */ $query .= " ORDER BY `pm_parent` DESC, `pm_order` "; // echo sprintf('
%s
', str_replace("\t","",$query)); $pst = $dbh->prepare($query); $pst->execute(); if($pst->rowCount() !== 0){ $i = 0; $i = 0; $Parent = null; $Data = array(); while($res = $pst->fetch(PDO::FETCH_ASSOC)){ switch($res['pm_id']){ case 1 : $desc = _('Betalning med konto -eller kreditkort. '); break; case 709 : $desc = _('Betalning med Swish på telefon/surfplatta.'); break; case 708 : $desc = _('Betalning via bank/plusgiro eller banköverföring.'); break; default : $desc = null; } $Data[$i] = array( "Id" => (int)$res['pm_id'], "Parent" => (int)$res['pm_parent'], "Name" => $res['pm_name'], "Desc" => $desc, "Fee" => 0, ); if((int)$res['pm_fee'] !== 0) $Data[$i]['Fee'] = $res['pm_fee'] + ($res['pm_fee'] * ($__NOTIFIES_VAT / 100)); $i++; } return $Data; } $pst = null; return false; } /* country list -- ------------------------------*/ public static function Countries(){ $dbh = Database::getInstance(); $Data = array(); global $currentLanguage,$Phrases; $query = " SELECT `area_code`, `iso_code`, `name`, `name_en`, IF(`iso_code` IN ('SE','DK','FI','NO'), 1, 0) `Scandinavia` FROM `system_country` ORDER BY CASE WHEN `Scandinavia` = 1 THEN 0 ELSE 1 END, CONVERT(`name` USING `latin1`) COLLATE `latin1_swedish_ci` ASC "; $pst = $dbh->query($query); if($pst->rowCount() === 0) return array(); $i = 0; $Curr = -1; while($res = $pst->fetch(PDO::FETCH_ASSOC)){ if($Curr !== (int)$res['Scandinavia']){ if($Curr !== -1) $i++; $y = 0; $Data[$i] = array( "Label" => $Phrases[sprintf("LBL_COUNTRY_REGION_%d", $res['Scandinavia'])], "List" => array(), ); } $Data[$i]['List'][$y] = array( "iso" => $res['iso_code'], "name" => $res['name'], "code" => (int)$res['area_code'], ); if($currentLanguage['Code'] !== 'sv') $Data[$i]['List'][$y]['name'] = $res['name_en']; $Curr = (int)$res['Scandinavia']; $y++; } $pst = null; return $Data; } /* country list 'flat' -- ------------------------------*/ public static function CountriesFlat(){ $dbh = Database::getInstance(); $Data = array(); $query = " SELECT `area_code`, `iso_code`, `name`, `name_en` FROM `system_country` ORDER BY CONVERT(`name` USING `latin1`) COLLATE `latin1_swedish_ci` ASC "; $pst = $dbh->query($query); if($pst->rowCount() === 0) return array(); $i = 0; while($res = $pst->fetch(PDO::FETCH_ASSOC)){ $Data[$res['iso_code']] = $res['name']; } $pst = null; return $Data; } /* roller -- ------------------------------*/ public static function Roles(){ $dbh = Database::getInstance(); $Data = []; $RFRoleTypeCatMapping = [ 0 => 12, 1 => 7 ]; $query = "SELECT `ID`, `Staff`, `Name`, `MemberFee`, `License`, `Invoice`, `Color`, `Props`, `Order` FROM `roles` ORDER BY `Staff`, `Order`"; foreach($dbh->query($query, PDO::FETCH_ASSOC) as $res){ $Removed = 0; $RFRoleTypeCatId = $RFRoleTypeCatMapping[$res['Staff']]; if(!is_null($res['Props']) && false !== $P = @unserialize($res['Props'])){ if(isset($P['RFRoleTypeCategoryId'])) $RFRoleTypeCatId = $P['RFRoleTypeCategoryId']; if(isset($P['Removed'])) $Removed = 1; } $Data[$res['Staff']][] = [ 'id' => (int)$res['ID'], 'staff' => (int)$res['Staff'] === 1, 'rf_role_type_cat_id' => $RFRoleTypeCatId, 'name' => $res['Name'], 'memberfee' => ((int)$res['MemberFee'] === 1), 'license' => ((int)$res['License'] === 1), 'invoice' => ((int)$res['Invoice'] === 1), 'color' => $res['Color'], 'order' => (int)$res['Order'], 'Removed' => $Removed ]; } return $Data; } public static function IsSerialized($data){ // if it isn't a string, it isn't serialized if ( !is_string( $data ) ) return false; $data = trim( $data ); if ( 'N;' == $data ) return true; if ( !preg_match( '/^([adObis]):/', $data, $badions ) ) return false; switch ( $badions[1] ) { case 'a' : case 'O' : case 's' : if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) ) return true; break; case 'b' : case 'i' : case 'd' : if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) ) return true; break; } return false; } /* options -- ----------*/ public static function get_option($option_name){ $dbh = Database::getInstance(); $pst = $dbh->prepare("SELECT `option_value` FROM `content_options` WHERE `option_name` = ?"); $pst->execute(array($option_name)); if($pst->rowCount() !== 0){ return @unserialize($pst->fetchColumn()); } $pst = null; return false; } public static function set_option($option_name, $data){ $dbh = Database::getInstance(); if(is_array($data) || is_object($data)){ if(false === $D = @serialize($data)) return false; $option_data = $D; }elseif(is_int($data)){ $option_data = (int)$data; }elseif(is_null($data)){ $option_data = null; }else{ $option_data = (string)$data; } $pst = $dbh->prepare(" INSERT INTO `content_options` (`option_name`, `option_value`) VALUES (:name, :content) ON DUPLICATE KEY UPDATE `option_value` = :content "); $pst->execute(array(':name' => $option_name, ':content' => $option_data)); return $pst->rowCount() !== 0; $pst = null; } } Class KOCommonException extends Exception { public function __construct($Msg) { /* call the super class Exception constructor */ parent::__construct($Msg, 0); } } /* tags system -- -------------------*/ Class SectionTags { /* lista -- -------*/ public static function TagList($Selected = array()){ $dbh = Database::getInstance(); $Data = array( array( "MenuId" => 0, "Section" => 0, "Name" => _('Huvudsida'), ) ); $pst = $dbh->prepare(" SELECT `ID`, `Section`, `Name` FROM `content_menu` ORDER BY `Order` ASC "); $pst->execute(); if($pst->rowCount() === 0) return false; while($res = $pst->fetch(PDO::FETCH_ASSOC)) $Data[] = array( "MenuId" => (int)$res['ID'], "Section" => (int)$res['Section'], "Name" => $res['Name'], ); return $Data; $pst = null; } /* hämta id -- -------*/ public static function GetIds($Type = 'news', $Parent = 0){ $dbh = Database::getInstance(); $pst = $dbh->prepare(" SELECT `SectionId` FROM `content_tag` WHERE `Type` = ? AND `Parent` = ? "); $pst->execute(array($Type, $Parent)); if($pst->rowCount() === 0) array(); $Data = array(); while($res = $pst->fetch(PDO::FETCH_ASSOC)) $Data[] = (int)$res['SectionId']; return $Data; $pst = null; } /* hämta name -- -------*/ public static function GetNames($Type = 'news', $Parent = 0){ $dbh = Database::getInstance(); $pst = $dbh->prepare(" SELECT IFNULL(`section_name`, 'Huvudsida') `section_name` FROM `content_tag` LEFT JOIN `school_section` ON `SectionId` = `section_id` WHERE `Type` = ? AND `Parent` = ? ORDER BY CONVERT(`section_name` USING `latin1`) COLLATE `latin1_swedish_ci` "); $pst->execute(array($Type, $Parent)); if($pst->rowCount() === 0) return false; $Data = array(); while($res = $pst->fetch(PDO::FETCH_ASSOC)) $Data[] = $res['section_name']; return $Data; $pst = null; } /* spara -- -------*/ public static function Save($SectionIds = array(), $Type = 'news', $Parent = 0){ $dbh = Database::getInstance(); $pst = $dbh->prepare(" DELETE FROM `content_tag` WHERE `Type` = ? AND `Parent` = ? "); $pst->execute(array($Type, $Parent)); $i = 0; $pst = $dbh->prepare(" INSERT INTO `content_tag` (`SectionId`, `Type`, `Parent`) VALUES (?, ?, ?) "); foreach($SectionIds as $Id){ // if((int)$Id === 0) continue; $pst->execute(array($Id, $Type, $Parent)); $i += $pst->rowCount(); } return ($i !== 0); } } ry($query, PDO::FETCH_ASSOC) as $res){ $Removed = 0; $RFRoleTypeCatId = $RFRoleTypeCatMapping[$res['Staff']]; if(!is_null($res['Props']) && false !== $P = @unserialize($res['Props'])){ if(isset($P['RFRoleTypeCategoryId'])) $RFRoleTypeCatId = $P['RFRoleTypeCategoryId']; if(isset($P['Removed'])) $Removed = 1; } $Data[$res['Staff']][] = [ 'id' => (int)$res['ID'], 'staff' => (int)$res['Staff'] === 1, 'rf_role_type_cat_id' => $RFRoleTypeCatId, 'name' => $res['Name'], 'memberfee' => ((int)$res['MemberFee'] === 1), 'license' => ((int)$res['License'] === 1), 'invoice' => ((int)$res['Invoice'] === 1), 'color' => $res['Color'], 'order' => (int)$res['Order'], 'Removed' => $Removed ]; } return $Data; } public static function IsSerialized($data){ // if it isn't a string, it isn't serialized if ( !is_string( $data ) ) return false; $data = trim( $data ); if ( 'N;' == $data ) return true; if ( !preg_match( '/^([adObis]):/', $data, $badions ) ) return false; switch ( $badions[1] ) { case 'a' : case 'O' : case 's' : if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) ) return true; break; case 'b' : case 'i' : case 'd' : if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) ) return true; break; } return false; } /* options -- ----------*/ public static function get_option($option_name){ $dbh = Database::getInstance(); $pst = $dbh->prepare("SELECT `option_value` FROM `content_options` WHERE `option_name` = ?"); $pst->execute(array($option_name)); if($pst->rowCount() !== 0){ return @unserialize($pst->fetchColumn()); } $pst = null; return false; } public static function set_option($option_name, $data){ $dbh = Database::getInstance(); if(is_array($data) || is_object($data)){ if(false === $D = @serialize($data)) return false; $option_data = $D; }elseif(is_int($data)){ $option_data = (int)$data; }elseif(is_null($data)){ $option_data = null; }else{ $option_data = (string)$data; } $pst = $dbh->prepare(" INSERT INTO `content_options` (`option_name`, `option_value`) VALUES (:name, :content) ON DUPLICATE KEY UPDATE `option_value` = :content "); $pst->execute(array(':name' => $option_name, ':content' => $option_data)); return $pst->rowCount() !== 0; $pst = null; } } Class KOCommonException extends Exception { public function __construct($Msg) { /* call the super class Exception constructor */ parent::__construct($Msg, 0); } } /* tags system -- -------------------*/ Class SectionTags { /* lista -- -------*/ public static function TagList($Selected = array()){ $dbh = Database::getInstance(); $Data = array( array( "MenuId" => 0, "Section" => 0, "Name" => _('Huvudsida'), ) ); $pst = $dbh->prepare(" SELECT `ID`, `Section`, `Name` FROM `content_menu` ORDER BY `Order` ASC "); $pst->execute(); if($pst->rowCount() === 0) return false; while($res = $pst->fetch(PDO::FETCH_ASSOC)) $Data[] = array( "MenuId" => (int)$res['ID'], "Section" => (int)$res['Section'], "Name" => $res['Name'], ); return $Data; $pst = null; } /* hämta id -- -------*/ public static function GetIds($Type = 'news', $Parent = 0){ $dbh = Database::getInstance(); $pst = $dbh->prepare(" SELECT `SectionId` FROM `content_tag` WHERE `Type` = ? AND `Parent` = ? "); $pst->execute(array($Type, $Parent)); if($pst->rowCount() === 0) array(); $Data = array(); while($res = $pst->fetch(PDO::FETCH_ASSOC)) $Data[] = (int)$res['SectionId']; return $Data; $pst = null; } /* hämta name -- -------*/ public static function GetNames($Type = 'news', $Parent = 0){ $dbh = Database::getInstance(); $pst = $dbh->prepare(" SELECT IFNULL(`section_name`, 'Huvudsida') `section_name` FROM `content_tag` LEFT JOIN `school_section` ON `SectionId` = `section_id` WHERE `Type` = ? AND `Parent` = ? ORDER BY CONVERT(`section_name` USING `latin1`) COLLA/* födelsedag -- ---------*/ if($this->authMethod === 2 && false === (bool)preg_match(REGEX_DATE, $User['user_birthdate'])) $this->errorMsg[] = "Ange födelsedag."; /* telefon -- ---------*/ if(/*$User['user_country'] === 'SE' */substr($User['user_phone2'], 0, 2) === '46' && false === (bool)preg_match(REGEX_CELLPHONE, preg_replace("/[^0-9]/", "", $User['user_phone2']))){ $this->errorMsg[] = sprintf("%s: %s", $this->Phrases['FORM_LBL_CELLPHONE'], "Telefonnummer är felaktigt."); } /* e-post -- ---------*/ if((bool)Swift_Validate::email($User['user_email']) === false){ $this->errorMsg[] = sprintf("%s: %s", $this->Phrases['FORM_LBL_EMAIL'], $this->Phrases['LBL_EMAIL_IS_INVALID']); } /* målsman -- ---------*/ if($this->authMethod !== 2 && $User['Age'] < 18) if((int)$User['Guardian'] === 0) $this->errorMsg[] = "Deltagaren är under 18år, ange minst 1 målsman/vårdnadshavare."; return (sizeof($this->errorMsg) === 0); } public function getErrorMsg(){ /* foreach($this->errorMsg as $key => $val){ $this->errorMsg[$key] = addslashes($this->errorMsg[$key]); } return $this->errorMsg; */ return array( "Message" => $this->errorMsg, "Field" => $this->errorFld, ); } public function getErrorFld(){ return $this->errorFld; } } Class KOAccountException extends Exception { public function __construct($Msg) { /* call the super class Exception constructor */ parent::__construct($Msg, 0); } }ry($query, PDO::FETCH_ASSOC) as $res){ $Removed = 0; $RFRoleTypeCatId = $RFRoleTypeCatMapping[$res['Staff']]; if(!is_null($res['Props']) && false !== $P = @unserialize($res['Props'])){ if(isset($P['RFRoleTypeCategoryId'])) $RFRoleTypeCatId = $P['RFRoleTypeCategoryId']; if(isset($P['Removed'])) $Removed = 1; } $Data[$res['Staff']][] = [ 'id' => (int)$res['ID'], 'staff' => (int)$res['Staff'] === 1, 'rf_role_type_cat_id' => $RFRoleTypeCatId, 'name' => $res['Name'], 'memberfee' => ((int)$res['MemberFee'] === 1), 'license' => ((int)$res['License'] === 1), 'invoice' => ((int)$res['Invoice'] === 1), 'color' => $res['Color'], 'order' => (int)$res['Order'], 'Removed' => $Removed ]; } return $Data; } public static function IsSerialized($data){ // if it isn't a string, it isn't serialized if ( !is_string( $data ) ) return false; $data = trim( $data ); if ( 'N;' == $data ) return true; if ( !preg_match( '/^([adObis]):/', $data, $badions ) ) return false; switch ( $badions[1] ) { case 'a' : case 'O' : case 's' : if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) ) return true; break; case 'b' : case 'i' : case 'd' : if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) ) return true; break; } return false; } /* options -- ----------*/ public static function get_option($option_name){ $dbh = Database::getInstance(); $pst = $dbh->prepare("SELECT `option_value` FROM `content_options` WHERE `option_name` = ?"); $pst->execute(array($option_name)); if($pst->rowCount() !== 0){ return @unserialize($pst->fetchColumn()); } $pst = null; return false; } public static function set_option($option_name, $data){ $dbh = Database::getInstance(); if(is_array($data) || is_object($data)){ if(false === $D = @serialize($data)) return false; $option_data = $D; }elseif(is_int($data)){ $option_data = (int)$data; }elseif(is_null($data)){ $option_data = null; }else{ $option_data = (string)$data; } $pst = $dbh->prepare(" INSERT INTO `content_options` (`option_name`, `option_value`) VALUES (:name, :content) ON DUPLICATE KEY UPDATE `option_value` = :content "); $pst->execute(array(':name' => $option_name, ':content' => $option_data)); return $pst->rowCount() !== 0; $pst = null; } } Class KOCommonException extends Exception { public function __construct($Msg) { /* call the super class Exception constructor */ parent::__construct($Msg, 0); } } /* tags system -- -------------------*/ Class SectionTags { /* lista -- -------*/ public static function TagList($Selected = array()){ $dbh = Database::getInstance(); $Data = array( array( "MenuId" => 0, "Section" => 0, "Name" => _('Huvudsida'), ) ); $pst = $dbh->prepare(" SELECT `ID`, `Section`, `Name` FROM `content_menu` ORDER BY `Order` ASC "); $pst->execute(); if($pst->rowCount() === 0) return false; while($res = $pst->fetch(PDO::FETCH_ASSOC)) $Data[] = array( "MenuId" => (int)$res['ID'], "Section" => (int)$res['Section'], "Name" => $res['Name'], ); return $Data; $pst = null; } /* hämta id -- -------*/ public static function GetIds($Type = 'news', $Parent = 0){ $dbh = Database::getInstance(); $pst = $dbh->prepare(" SELECT `SectionId` FROM `content_tag` WHERE `Type` = ? AND `Parent` = ? "); $pst->execute(array($Type, $Parent)); if($pst->rowCount() === 0) array(); $Data = array(); while($res = $pst->fetch(PDO::FETCH_ASSOC)) $Data[] = (int)$res['SectionId']; return $Data; $pst = null; } /* hämta name -- -------*/ public static function GetNames($Type = 'news', $Parent = 0){ $dbh = Database::getInstance(); $pst = $dbh->prepare(" SELECT IFNULL(`section_name`, 'Huvudsida') `section_name` FROM `content_tag` LEFT JOIN `school_section` ON `SectionId` = `section_id` WHERE `Type` = ? AND `Parent` = ? ORDER BY CONVERT(`section_name` USING `latin1`) COLLA/* födelsedag -- ---------*/ if($this->authMethod === 2 && false === (bool)preg_match(REGEX_DATE, $User['user_birthdate'])) $this->errorMsg[] = "Ange födelsedag."; /* telefon -- ---------*/ if(/*$User['user_country'] === 'SE' */substr($User['user_phone2'], 0, 2) === '46' && false === (bool)preg_match(REGEX_CELLPHONE, preg_replace("/[^0-9]/", "", $User['user_phone2']))){ $this->errorMsg[] = sprintf("%s: %s", $this->Phrases['FORM_LBL_CELLPHONE'], "Telefonnummer är felaktigt."); } /* e-post -- ---------*/ if((bool)Swift_Validate::email($User['user_email']) === false){ $this->errorMsg[] = sprintf("%s: %s", $this->Phrases['FORM_LBL_EMAIL'], $this->Phrases['LBL_EMAIL_IS_INVALID']); } /* målsman -- ---------*/ if($this->authMethod !== 2 && $User['Age'] < 18) if((int)$User['Guardian'] === 0) $this->errorMsg[] = "Deltagaren är under 18år, ange minst 1 målsman/vårdnadshavare."; return (sizeof($this->errorMsg) === 0); } public function getErrorMsg(){ /* foreach($this->errorMsg as $key => $val){ $this->errorMsg[$key] = addslashes($this->errorMsg[$key]); } return $this->errorMsg; */ return array( "Message" => $this->errorMsg, "Field" => $this->errorFld, ); } public function getErrorFld(){ return $this->errorFld; } } Class KOAccountException extends Exception { public function __construct($Msg) { /* call the super class Exception constructor */ parent::__construct($Msg, 0); } }ry($query, PDO::FETCH_ASSOC) as $res){ $Removed = 0; $RFRoleTypeCatId = $RFRoleTypeCatMapping[$res['Staff']]; if(!is_null($res['Props']) && false !== $P = @unserialize($res['Props'])){ if(isset($P['RFRoleTypeCategoryId'])) $RFRoleTypeCatId = $P['RFRoleTypeCategoryId']; if(isset($P['Removed'])) $Removed = 1; } $Data[$res['Staff']][] = [ 'id' => (int)$res['ID'], 'staff' => (int)$res['Staff'] === 1, 'rf_role_type_cat_id' => $RFRoleTypeCatId, 'name' => $res['Name'], 'memberfee' => ((int)$res['MemberFee'] === 1), 'license' => ((int)$res['License'] === 1), 'invoice' => ((int)$res['Invoice'] === 1), 'color' => $res['Color'], 'order' => (int)$res['Order'], 'Removed' => $Removed ]; } return $Data; } public static function IsSerialized($data){ // if it isn't a string, it isn't serialized if ( !is_string( $data ) ) return false; $data = trim( $data ); if ( 'N;' == $data ) return true; if ( !preg_match( '/^([adObis]):/', $data, $badions ) ) return false; switch ( $badions[1] ) { case 'a' : case 'O' : case 's' : if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) ) return true; break; case 'b' : case 'i' : case 'd' : if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) ) return true; break; } return false; } /* options -- ----------*/ public static function get_option($option_name){ $dbh = Database::getInstance(); $pst = $dbh->prepare("SELECT `option_value` FROM `content_options` WHERE `option_name` = ?"); $pst->execute(array($option_name)); if($pst->rowCount() !== 0){ return @unserialize($pst->fetchColumn()); } $pst = null; return false; } public static function set_option($option_name, $data){ $dbh = Database::getInstance(); if(is_array($data) || is_object($data)){ if(false === $D = @serialize($data)) return false; $option_data = $D; }elseif(is_int($data)){ $option_data = (int)$data; }elseif(is_null($data)){ $option_data = null; }else{ $option_data = (string)$data; } $pst = $dbh->prepare(" INSERT INTO `content_options` (`option_name`, `option_value`) VALUES (:name, :content) ON DUPLICATE KEY UPDATE `option_value` = :content "); $pst->execute(array(':name' => $option_name, ':content' => $option_data)); return $pst->rowCount() !== 0; $pst = null; } } Class KOCommonException extends Exception { public function __construct($Msg) { /* call the super class Exception constructor */ parent::__construct($Msg, 0); } } /* tags system -- -------------------*/ Class SectionTags { /* lista -- -------*/ public static function TagList($Selected = array()){ $dbh = Database::getInstance(); $Data = array( array( "MenuId" => 0, "Section" => 0, "Name" => _('Huvudsida'), ) ); $pst = $dbh->prepare(" SELECT `ID`, `Section`, `Name` FROM `content_menu` ORDER BY `Order` ASC "); $pst->execute(); if($pst->rowCount() === 0) return false; while($res = $pst->fetch(PDO::FETCH_ASSOC)) $Data[] = array( "MenuId" => (int)$res['ID'], "Section" => (int)$res['Section'], "Name" => $res['Name'], ); return $Data; $pst = null; } /* hämta id -- -------*/ public static function GetIds($Type = 'news', $Parent = 0){ $dbh = Database::getInstance(); $pst = $dbh->prepare(" SELECT `SectionId` FROM `content_tag` WHERE `Type` = ? AND `Parent` = ? "); $pst->execute(array($Type, $Parent)); if($pst->rowCount() === 0) array(); $Data = array(); while($res = $pst->fetch(PDO::FETCH_ASSOC)) $Data[] = (int)$res['SectionId']; return $Data; $pst = null; } /* hämta name -- -------*/ public static function GetNames($Type = 'news', $Parent = 0){ $dbh = Database::getInstance(); $pst = $dbh->prepare(" SELECT IFNULL(`section_name`, 'Huvudsida') `section_name` FROM `content_tag` LEFT JOIN `school_section` ON `SectionId` = `section_id` WHERE `Type` = ? AND `Parent` = ? ORDER BY CONVERT(`section_name` USING `latin1`) COLLA/* födelsedag -- ---------*/ if($this->authMethod === 2 && false === (bool)preg_match(REGEX_DATE, $User['user_birthdate'])) $this->errorMsg[] = "Ange födelsedag."; /* telefon -- ---------*/ if(/*$User['user_country'] === 'SE' */substr($User['user_phone2'], 0, 2) === '46' && false === (bool)preg_match(REGEX_CELLPHONE, preg_replace("/[^0-9]/", "", $User['user_phone2']))){ $this->errorMsg[] = sprintf("%s: %s", $this->Phrases['FORM_LBL_CELLPHONE'], "Telefonnummer är felaktigt."); } /* e-post -- ---------*/ if((bool)Swift_Validate::email($User['user_email']) === false){ $this->errorMsg[] = sprintf("%s: %s", $this->Phrases['FORM_LBL_EMAIL'], $this->Phrases['LBL_EMAIL_IS_INVALID']); }/* födelsedag -- ---------*/ if($this->authMethod === 2 && false === (bool)preg_match(REGEX_DATE, $User['user_birthdate'])) $this->errorMsg[] = "Ange födelsedag."; /* telefon -- ---------*/ if(/*$User['user_country'] === 'SE' */substr($User['user_phone2'], 0, 2) === '46' && false === (bool)preg_match(REGEX_CELLPHONE, preg_replace("/[^0-9]/", "", $User['user_phone2']))){ $this->errorMsg[] = sprintf("%s: %s", $this->Phrases['FORM_LBL_CELLPHONE'], "Telefonnummer är felaktigt."); } /* e-post -- ---------*/ if((bool)Swift_Validate::email($User['user_email']) === false){ $this->errorMsg[] = sprintf("%s: %s", $this->Phrases['FORM_LBL_EMAIL'], $this->Phrases['LBL_EMAIL_IS_INVALID']); } /* målsman -- ---------*/ if($this->authMethod !== 2 && $User['Age'] < 18) if((int)$User['Guardian'] === 0) $this->errorMsg[] = "Deltagaren är under 18år, ange minst 1 målsman/vårdnadshavare."; return (sizeof($this->errorMsg) === 0); } public function getErrorMsg(){ /* foreach($this->errorMsg as $key => $val){ $this->errorMsg[$key] = addslashes($this->errorMsg[$key]); } return $this->errorMsg; */ return array( "Message" => $this->errorMsg, "Field" => $this->errorFld, ); } public function getErrorFld(){ return $this->errorFld; } } Class KOAccountException extends Exception { public function __construct($Msg) { /* call the super class Exception constructor */ parent::__construct($Msg, 0); } }es[] references * * @var string */ public $_pattern = '(\$matches\[[1-9]+[0-9]*\])'; // magic number /** * constructor * * @param string $subject subject if regex * @param array $matches data to use in map */ public function __construct($subject, $matches) { $this->_subject = $subject; $this->_matches = $matches; $this->output = $this->_map(); } /** * Substitute substring matches in subject. * * static helper function to ease use * * @static * @access public * * @param string $subject subject * @param array $matches data used for substitution * @return string */ public static function apply($subject, $matches) { $oSelf = new KO_MapRegex($subject, $matches); return $oSelf->output; } /** * do the actual mapping * * @access private * @return string */ private function _map() { $callback = array($this, 'callback'); return preg_replace_callback($this->_pattern, $callback, $this->_subject); } /** * preg_replace_callback hook * * @access public * @param array $matches preg_replace regexp matches * @return string */ public function callback($matches) { $index = intval(substr($matches[0], 9, -1)); return ( isset( $this->_matches[$index] ) ? urlencode($this->_matches[$index]) : '' ); } } ?>evels'][$k]['Period']); if($No === 0) unset($Data[$i]['Types'][$j]['Levels'][$k]); } $No = sizeof($Data[$i]['Types'][$j]['Levels']); if($No === 0) unset($Data[$i]['Types'][$j]); } $No = sizeof($Data[$i]['Types']); if($No === 0) unset($Data[$i]); } // echo "\n\n"; // echo sprintf("
%s
", print_r($Data, true)); exit; // exit; /* for($i = 0; $i < count($Data); $i++){ if(!isset($Data[$i]['Period'])) break; for($j = 0; $j <= count($Data[$i]['Period']); $j++){ if(sizeof($Data[$i]['Period']) === 1 && sizeof($Data[$i]['Period'][$j]['Groups']) === 0){ unset($Data[$i]); break; } } } */ $Data = array_values($Data); $Sb = "\n\t 3) $Max = 3; for($i = 0; $i <= $Max; $i++){ echo sprintf("%d\t%d\t%s\n", $i, $Data[$i]['Id'], $Data[$i]['Name']); } if(count($Data) !== $i && count($Data) - $i === 1){ for($j = $i; $j < count($Data); $j++){ echo sprintf("%d\t%d\t%s\n", $j, $Data[$j]['Id'], $Data[$j]['Name']); } $i = $j; }elseif(count($Data) !== $i && count($Data) - $i > 1){ echo "FLER\n"; for($j = $i; $j < count($Data); $j++){ echo sprintf("%d\t%d\t%s\n", $j, $Data[$j]['Id'], $Data[$j]['Name']); } $i = $j; } echo "\n"; echo sprintf("ANT: %d\nMAX: %d\n\n", count($Data), $i); echo "\n"; var_dump((bool)($i === count($Data))); echo "\n\n"; echo sprintf("ANT: %d\nMAX: %d\n\n", count($Data), $i); echo "\n"; var_dump((bool)($i === count($Data))); echo "\n\n"; exit; */ /* antal att visa -- ---------------*/ $Max = count($Data); if($Max > 5) $Max = 5; /* anmälan -- ---------*/ if(false !== $NotifyUrl = $this->NavigateUrl('school.notify.php')) $Sb .= sprintf('', $NotifyUrl, _('Anmälan')); for($i = 0; $i <= $Max-1; $i++){ if(!isset($Data[$i])) continue; $Sb .= << {$Data[$i]['Name']} \n"; return $Sb; } public function MetisTree($Data, $Start = 1){ $Sb = "MenuPrefix; if(strlen($MenuClassName) !== 0) $MenuClassName = sprintf(" %s", $MenuClassName); $Sb .= sprintf(" id=\"menu\" class=\"metismenu%s\"", $MenuClassName); $MenuClassName = ""; } $Sb .= ">\n"; $AuthPattern = $this->AuthPattern(); $Data = $this->SanitizeMenu($Data); foreach($Data as $No => $Item){ if(!preg_match("/{$AuthPattern}/", $Item['Auth'])){ unset($Item); continue; } $Sb .= "
  • "; $Sb .= $this->NavType($Item, (sizeof($Item['Child']) !== 0)); if(is_array($Item['Child']) && sizeof($Item['Child']) != 0){ $Sb .= $this->ParseTreeView($Iteis->__CLIENT_LONG_NAME}" rel="home"> Logotype

    Saltsjöbadens IF

    Fotbollssektionen
    \n */ $this->Styles[] = '.header-image-wrap { padding: 15px 10px; }'; $Output = <<\n EOT; if( isset($this->Data->Logotype) && file_exists(sprintf("%s%s%s", ROOTPATH, SKINPATH, $this->Data->Logotype)) ){ $Logotype = sprintf("%s%s%s", ABSPATH, SKINPATH, $this->Data->Logotype); /* is svg? -- ----------*/ /* if(true !== (bool)preg_match("/.*(\.svg)$/i", $this->Data->Logotype)){ $Output .= << Your browser does not support SVG \n EOT; }else{ */ $t = time(); $Output .= << {{LongName}}-logotype \n EOT; //} } if(isset($this->Data->TxtVisible) && $this->Data->TxtVisible === true){ $this->Styles[] = sprintf('.header-image-wrap .site-brand a, .header-image-wrap .site-brand small { color: #%s; }', $this->Data->TxtColor); if(isset($this->Data->TxtShadow) && (int)$this->Data->TxtShadow === 1) $this->Styles[] = '.header-image-wrap .site-brand, .header-image-wrap .site-brand small { text-shadow: 2px 2px 1px rgba(100, 100, 100, 0.1); text-shadow: 2px 2px 1px rgba(0, 0, 0, .2); }'; $Output .= << {{LongName}} \n EOT; if(strlen($this->__CLIENT_DESC) !== 0) $Output .= " {{Desc}}\n"; $Output .= <<\n EOT; } $Output .= <<\n EOT; }elseif($this->Data->Type === 'modern'){ }else{ $Output .= << {{LongName}} \n EOT; return ""; } $Css = << li > a {color:#[TXT];text-shadow: none;} [PREFIX] .navbar .navbar-brand:hover, [PREFIX] .navbar .navbar-nav > li > a:hover, [PREFIX] .navbar .navbar-nav > .open > a, [PREFIX] .navbar .navbar-nav > .open > a:focus, [PREFIX] .navbar .navbar-nav > .open > a:hover{color:#[BACKGROUND];background-color:#[TXT];background-image:none;text-shadow:none;box-shadow:none} [PREFIX] .navbar .open > a, [PREFIX] .navbar .open > a:focus, [PREFIX] .navbar .open > a:hover{color:#[TXT];background-color:#[BACKGROUND];background-image:none} [PREFIX] .navbar .dropdown-menu > li > a:focus, [PREFIX] .navbar .dropdown-menu > li > a:hover{color:#[TXT];background-color:#[BACKGROUND];background-image:none} [PREFIX] .navbar .dropdown-menu > .active > a, [PREFIX] .navbar .dropdown-menu > .active > a:focus, [PREFIX] .navbar .dropdown-menu > .active > a:hover{color:#[BACKGROUND];background-color:#[TXT];background-image:none} @media (max-width: 767px){[PREFIX] .navbar .navbar-nav .open .dropdown-menu > li > a{color:#[TXT];background-color:#[BACKGROUND];background-image:none;text-shadow:none;box-shadow:none}[PREFIX] .navbar .navbar-nav .open .dropdown-menu > li > a:focus,[PREFIuser_id` = {$this->UserId} LIMIT 1 "; $Result = mysql_query($query) or die((DEBUG ? sprintf('%s\n%s\n\n%s', _('Ett fel uppstod'), mysql_error(), str_replace("\t", "", $query)) : _('Ett fel uppstod, kontakta supporten.'))); if(!(mysql_num_rows($Result) == false)) $Params['MemType'] = (int)mysql_result($Result, 0); mysql_free_result($Result); return $Params; } private function ParseShop($Path = "", $Parent = 0, $Template = 1){ $Data = array( /* array( "Id" => 0, "Parent" => $Parent, "Name" => "", "Text" => null, "RegEx" => null, "Auth" => 1, "Path" => "{$Path}kundvagn/", "Template" => $Template, "MenuItem" => "", "Page" => array( "Id" => 0, "Name" => "shop.cart.php", ), "Type" => 'published', "InMenu" => 1, "IsActive" => 2, "Child" => array(), ), array( "Id" => 0, "Parent" => $Parent, "Name" => "", "Text" => null, "RegEx" => null, "Auth" => 1, "Path" => "{$Path}kassa/", "Template" => $Template, "MenuItem" => "", "Page" => array( "Id" => 0, "Name" => "shop.cashier.php", ), "Type" => 'published', "InMenu" => 1, "IsActive" => 2, "Child" => array(), ), */ ); $Conds = array(); $Params = $this->UserParams(); if(!is_null($Params)){ $Parts = array(); if(isset($Params['MemType']) && (int)$Params['MemType'] !== 0) $Parts[] = " (`MemType` = {$Params['MemType']}) "; if(isset($Params['Level']) && sizeof($Params['Level']) !== 0){ $Levels = implode(",", $Params['Level']); $Parts[] = " (`LevelId` IN( {$Levels} )) "; } foreach($Parts as $Key => $Part){ if($Key == 0){ $Conds[1] = "(\n" . $Part; continue; } $Conds[1] .= "\n OR \n" . $Part; } if(sizeof($Parts) !== 0) $Conds[1] .= "\n ) "; } $query = " SELECT DISTINCT `cat_id`, `cat_name` FROM `shop_category` INNER JOIN `shop_prod` `shop` ON `cat_id` = `shop`.`parent_id` LEFT JOIN `shop_resource` `resource` ON `shop`.`prod_id` = `resource`.`prod_id` LEFT JOIN `shop_category_lock` ON `cat_id` = `CatId` WHERE `resource`.`prod_id` IS NULL AND `shop`.`prod_removed` = 1 AND ( ( `cat_visible` = 2 )"; if(sizeof($Conds) !== 0){ $query .= " OR ( `cat_visible` = 3 "; foreach($Conds as $Cond) $query .= " AND {$Cond} \n"; $query .= " )"; } $query .= " ) AND `cat_removed` = 1 ORDER BY `cat_order` ASC "; // echo sprintf("
    %s
    ", $query); $result = mysql_query($query) or die((DEBUG ? "

    An error occurred

    \n

    " . mysql_error() . "
    \n" . $query . "

    \n" : "

    An error has occurred, please contact site admin.

    \n")); if(mysql_num_rows($result) !== false){ $i = 0; while($res = mysql_fetch_assoc($result)){ $Slug = post_slug($res['cat_name']); $Data[] = array( "Id" => 0, "Parent" => $Parent, "Name" => $res['cat_name'], "Text" => null, "RegEx" => null, "Auth" => 1, "Path" => "{$Path}{$Slug}/", "Template" => $Template, "MenuItem" => "", "Page" => array( "Id" => 0, "Name" => "shop.php", ), "CatId" => (int)$res['cat_id'], "Type" => 'published', "InMenu" => 2, "IsActive" => 2, "Child" => array(), ); $i++; } return $Data; } mysql_free_result($result); return false; } private function AuthPattern(){ switch($this->AuthType){ case 2 : $Auth = "^(1|2|5)$"; break; case 3 : $Auth = "^(1|3|5)$"; break; default : $Auth = "^(1|4)$"; } return $Auth; } } class KO_MapRegex { /** * store for matches * * @access private * @var array */ private $_matches; /** * store for mapping result * * @access public * @var string */ public $output; /** * subject to perform mapping on (query string containing $matches[] references * * @access private * @var string */ private $_subject; /** * regexp pattern to match $matches[] references * * @var string */ public $_pattern = '(\$matches\[[1-9]+[0-9]*\])'; // magic number /** * constructor * * @param string $subject subject if regex * @param array $matches data to use in map */ public function __construct($subject, $matches) { $this->_subject = $subject; $this->_matches = $matches; $this->output = $this->_map(); } /** * Substitute substring matches in subject. * * static helper function to ease use * * @static * @access public * * @param string $subject subject * @param array $matches data used for substitution * @return string */ public static function apply($subject, $matches) { $oSelf = new KO_MapRegex($subject, $matches); return $oSelf->output; } /** * do the actual mapping * * @access private * @return string */ private function _map() { $callback = array($this, 'callback'); return preg_replace_callback($this->_pattern, $callback, $this->_subject); } /** * preg_replace_callback hook * * @access public * @param array $matches preg_replace regexp matches * @return string */ public function callback($matches) { $index = intval(substr($matches[0], 9, -1)); return ( isset( $this->_matches[$index] ) ? urlencode($this->_matches[$index]) : '' ); } } ?>