'/\+([\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"), ); } 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_F=> 2000, 'height' => 800 ], 'news' => [ 'width' => 1200, 'height' => 630 ], 'school_level' => [ 'width' => 1200, 'height' => 630 ], // 'coverphoto' => [ 'width' => 1920, 'height' => 630 ] ]; /* local api -- -----------*/ if(!defined("KO_LOCAL_API_USER")) define("KO_LOCAL_API_USER", "KanslietAPI"); if(!defined("KO_LOCAL_API_PASS")) define("KO_LOCAL_API_PASS", "MyJD7a@s&x8zgF"); /* app -- -----------*/ if(!defined('KO_APP_URI')) define("KO_APP_URI", "https://app.kanslietonline.se"); if(!defined('WU_APP_URI')) define("WU_APP_URI", "https://prod.weunite.app"); define("KO_FIREBASE_KEY", 'AAAAuyVcS40:APA91bHgP_l5wXTpfBgh8uqUSfMOOFMBznweD4VLpfN0xScbMHX0Wz0gVSBlr7ZuiX9mcblax7cU6gEPU3cCMMycryncZhtwQwLtkOF4RPUxRabFEp-FzSVIBB0rRXMODOnm7IEVnKKd'); // depricated define('KO_FIREBASE_MESSAGE_URL', '192.168.137.70:8083/api/v1/firebase-msg/by-device'); /* e-post -- -----------*/ define("KO_MAIL_FROM", "svara-ej@epost.kanslietonline.se"); define("KO_MAIL_HOST", "epost.kanslietonline.se:465"); define("KO_MAIL_AUTH", true); define("KO_MAIL_USER", "svara-ej@epost.kanslietonline.se"); define("KO_MAIL_PASS", "arBiS&Wc5^KA7De2Z%J^C"); define("KO_MAIL_METH", "smtp"); define("KO_MAIL_SECURE", "tls"); /* newsletter -- -----------*/ define("KO_NEWSLETTER_URI", "https://nyhetsbrev.kanslietonline.se"); define("KO_DRIFT_URL", "https://drift.kanslietonline.se/"); define("KO_CDN_URL", "https://cdn.kanslietonline.se/"); /* ocr -- -----------*/ define('OCR_ACTIVATION_PASSWD', 'SkaffaOCRNU2015'); /* eventor -- -----------*/ define('EVENTOR_API_KEY', '9a7ccda282b1483aa76d9f06b99ad7ad'); /* help desk -- -----------*/ /* gamla -- ----- define('LA_URL','https://support.weunite.club/'); define('LA_APIv1','UKCYheyViJFD3ZTkmyDZvbPbXZ5t02Cw'); define('LA_APIv3','9vlp9wsbsmhosz1wufa4e4yki99arurq'); define('LA_SSO','l4rwep68tjyvncwce9po35enixml3dvf'); define('LA_CHAT_ID', 'aemlexf1'); */ /* nya -- -----*/ define('LA_URL','https://support.weunite.club/'); // https://weunite.ladesk.com/ define('LA_APIv1','FHuajSGFxvQC5gHOX1Qb8Qrc3REFwPJS'); define('LA_APIv3','iwj09c8flz4scdisk0da9skbhmei45gp'); define('LA_SSO','jdf0xarg9y5uy13os02u0fa9sw7up2r8'); define('LA_CHAT_ID', 'cgo9pg9j'); //define('KO_HELPDESK','Kayako'); if(!defined('KO_HELPDESK')) define('KO_HELPDESK','LiveAgent'); /* bokningsbara resurser -- ----------------------*/ $__global_resource_types = [ 1 => 'Motorbåt', 2 => 'Segelbåt', 3 => 'Kanot', ]; $__Pensum_Gymn = [ 'C' => 'Träning - fria volter oavsett redskap - ej tävling', 'TG' => 'Truppgymnastik', 'SA' => 'Aerobic Gymnastics', 'AG' => 'Artistisk Gymnastik', 'DR' => 'Drill', 'HR' => 'Hopprep', 'PK' => 'Parkour/tricking Tävling', 'RG' => 'Rytmisk Gymnastik', 'TM' => 'Trampolin', ]; $__IOSports = [ 54 => array ( 'name' => 'Akademisk Idrott', 'children' => array ( ), ), 68 => array ( 'name' => 'Amerikansk Fotboll', 'children' => array ( 445 => 'Blank tills hösten 2021 (BB)', 448 => 'Blank tills hösten 2021 (SB)', 446 => 'Idrott Amerikansk fotboll ', 444 => 'Idrott Flaggfotboll', 447 => 'Idrott Landhockey', ), ), 1 => array ( 'name' => 'Badminton', 'children' => array ( ), ), 5 => array ( 'name' => 'Bandy', 'children' => array ( ), ), 26 => array ( 'name' => 'Bangolf', 'children' => array ( ), ), 55 => array ( 'name' => 'Baseboll och Softboll', 'children' => array ( ), ), 10 => array ( 'name' => 'Basket', 'children' => array ( ), ), 57 => array ( 'name' => 'Biljard', 'children' => array ( ), ), 9 => array ( 'name' => 'Bilsport', 'children' => array ( ), ), 8 => array ( 'name' => 'Bordtennis', 'children' => array ( ), ), 66 => array ( 'name' => 'Boule', 'children' => array ( ) : '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"), ); } /* online payment -- ------------------------------*/ public static function OnlinePaymentIsEnabled(){ return ( defined('PSP') && PSP === 'SwedbankPay' ); } 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){ $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 gymnastik 7-12 år (ej tävling)', 276 => 'Barngymnastik upp till 6 år', 283 => 'Cheerleading-gy ', 357 => 'Drill', 277 => 'Familjegymnastik', 280 => 'Gruppträning/motion 21-64 år', 410 => 'Gymmixförening', 284 => 'Hopprep', 285 => 'Kvinnlig artistisk gymnastik', 286 => 'Manlig artistisk gymnastik', 405 => 'Parkour/freerunning', 287 => 'Rytmisk gymnastik', 281 => 'Seniorträning/gruppträning + 65 år', 288 => 'Trampolin', 407 => 'Tricking', 289 => 'Truppgymnastik', 279 => 'Ungdomsgymnastik 13-20 år (ej tävling)', 408 => 'Vuxenträning med gymnastikredskap', ), ), 12 => array ( 'name' => 'Gång och Vandring', 'children' => array ( ), ), 4 => array ( 'name' => 'Handboll', 'children' => array ( ), ), 61 => array ( 'name' => 'Innebandy', 'children' => array ( ), ), 416 => array ( 'name' => 'Intresseförening', 'children' => array ( ), ), 14 => array ( 'name' => 'Ishockey', 'children' => array ( ), ), 356 => array ( 'name' => 'Islandshäst', 'children' => array ( 415 => 'TREC', ), ), 38 => array ( 'name' => 'Issegling', 'children' => array ( ), ), 65 => array ( 'name' => 'Judo', 'children' => array ( ), ), 22 => array ( 'name' => 'Kanot', 'children' => array ( ), ), 89 => array ( 'name' => 'Karate', 'children' => array ( ), ), 48 => array ( 'name' => 'Klättring', 'children' => array ( ), ), 20 => array ( 'name' => 'Konståkning', 'children' => array ( ), ), 43 => array ( 'name' => 'Korpen', 'children' => array ( 238 => 'Aerobics', 239 => 'Afro', 336 => 'BMX (Korpen)', 263 => 'Badminton ( Korpen )', 352 => 'Bangolf (Korpen)', 264 => 'Basket ( Korpen )', 350 => 'Beachvolleyboll (Korpen)', 265 => 'Bordtennis ( Korpen )', 267 => 'Boule ( Korpen )', 266 => 'Bowling ( Korpen )', 240 => 'Box', 339 => 'Cirkelträning', 241 => 'Core (rygg/bål)', 330 => 'Curling (korpen)', 242 => 'Cykling', 102 => 'Five-a-side', 99 => 'Fotboll (Korpen)', 244 => 'Funktionell träning – EFIT', 101 => 'Futsal', 273 => 'Golf (Korpen)', 245 => 'Gym', 246 => 'Gympa', 104 => 'Handboll (Korpen)', 353 => 'Hockeybockey (Korpen)', 100 => 'Innebandy (Korpen)', 270 => 'Ishockey ( Korpen )', 349 => 'Kägel', 247 => 'Löpning', 329 => 'Paddling (Korpen)', 401 => 'Parkour', 248 => 'Pilates', 249 => 'Pump', 250 => 'Qi gong', 354 => 'Racketlon (Korpen)', 103 => 'Rinkbandy', 252 => 'Senioraktiviteter', 337 => 'Skateboard (Korpen)', 253 => 'Spinning', 271 => 'Squash ( Korpen )', 254 => 'Stavgång', 255 => 'Step', 256 => 'Streetdance', 389 => 'Taekwondo (Korpen)', 272 => 'Tennis ( Korpen )', 257 => 'Tipspromenad', 351 => 'Varpa (Korpen)', 258 => 'Vattenträning', 105 => 'Volleyboll (Korpen)', 259 => 'Yoga', 260 => 'Zumba / Latin moves', ), ), 3 => array ( 'name' => 'Kälksport', 'children' => array ( ), ), 62 => array ( 'name' => 'Landhockey', 'children' => array ( ), ), 159 => array ( 'name' => 'Livräddning', 'children' => array ( ), ), 28 => array ( 'name' => 'Motorcykel och Snöskoter', 'children' => array ( 450 => 'Aquabike', 118 => 'Dragracing', 117 => 'Enduro', 315 => 'Flat Track', 120 => 'Isracing', 121 => 'Minimoto', 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); } } 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); } } 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); } } 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))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); } }