示例#1
0
 function createResServ($MID, $authenticated = false)
 {
     chdir("/var/www/vhosts/biggleswadesc.org/subdomains/results.biggleswadesc.org/httpdocs/res");
     global $user;
     if (($user->accessPage(63) || $user->accessPage(64)) && !$authenticated || $authenticated) {
         $query = $this->mySQL['r']->prepare("SELECT `MID`,`meet`,`series`, from `comp_res` WHERE `MID`=? AND `enable`='1'");
         $query->bind_param('s', $MID);
         $query->execute();
         $query->store_result();
         if ($query->num_rows == 1) {
             $comp = new Meet($this->mySQL);
             $comp->setID($MID);
             $comp->createMeet();
             $query->bind_result($MID, $meet, $series);
             $query->fetch();
             if (!file_exists($meet)) {
                 mkdir($meet);
             } elseif (file_exists($meet) && !is_dir($meet)) {
                 unlink($meet);
                 mkdir($meet);
             }
             chdir($meet);
             if (!file_exists($series)) {
                 mkdir($series);
             } elseif (file_exists($series) && !is_dir($series)) {
                 unlink($series);
                 mkdir($series);
             }
             chdir($series);
             if ($comp_meet->res['indivSession']) {
                 foreach ($comp->meet['S'] as $i => $session) {
                     if (!file_exists('session' . $i)) {
                         mkdir('session' . $i);
                     } elseif (file_exists('session' . $i) && !is_dir('session' . $i)) {
                         unlink('session' . $i);
                         mkdir('session' . $i);
                     }
                 }
             }
             $meetFile = fopen('meet.php', 'w');
             $file = "<?php\n";
             $file .= "/*\n*\n* Meet Definition PHP File\n* Author: BWSC Website (Huw Jones)\n* (C) Biggleswade Swimming Club\n* File Created: " . date("H:i:s d/m/Y") . "\n*/\n";
             $file .= "\n/*\n* Version\n*/\n";
             $file .= "// 3 = Event titles are hardcoded into the meet.php file. These files have been created automatically\n";
             $file .= '$meet["version"]' . "\t\t\t\t" . '= 3;' . PHP_EOL;
             $file .= "\n/*\n* Core\n*/\n";
             $file .= "// Meet title \n";
             $file .= '$meet["core"]["title"]' . "\t\t\t" . '= "' . $comp->getTitle() . '";' . PHP_EOL;
             $file .= "// Meet title \n";
             $file .= '$meet["core"]["licence"]' . "\t\t" . '= "' . $comp->licence . '";' . PHP_EOL;
             $file .= "// Number of Sessions (For Continuity Checking)\n";
             $file .= '$meet["core"]["sessions"]' . "\t\t" . '= ' . $comp->getNumberSessions() . ';' . PHP_EOL;
             $file .= "// Number of Events (For Continuity Checking)\n";
             $file .= '$meet["core"]["events"]' . "\t\t\t" . '= ' . $comp->getNumberEvents() . ';' . PHP_EOL;
             $file .= "\n// Date\n";
             $file .= "// Set the date prefix for the event files. dd/mm/yyYY should be set as YYmmdd\n";
             $file .= '$meet["core"]["date"]["prefix"]' . "\t" . '= "' . date("ymd", strtotime($comp->getDates('s'))) . '";' . PHP_EOL;
             $file .= "// Start Date\n";
             $file .= '$meet["core"]["date"]["start"]' . "\t" . '= "' . $comp->getDates('s') . '";' . PHP_EOL;
             $file .= "// Finish Date\n";
             $file .= '$meet["core"]["date"]["finish"]' . "\t" . '= "' . $comp->getDates('f') . '";' . PHP_EOL;
             $file .= "// Individual Sessions\n";
             $file .= '$meet["core"]["indivSess"]' . "\t\t" . '= "' . $comp->resServ['indivSess'] . '";' . PHP_EOL;
             $file .= "// Next Session\n";
             $file .= '$meet["core"]["nextSession"]' . "\t" . '= "' . $comp->resServ['nextSession'] . '";' . PHP_EOL;
             $file .= "\n// Download Results\n";
             $file .= "// If you wish user to be able to download the results as PDFs, set to true.\n";
             $file .= "// If you are going to upload PDFs set to 'PDF', otherwise set to 'compile' and the service will compile the results files into PDFs on the fly.\n";
             $file .= '$meet["core"]["download"]' . "\t\t" . '= "' . strtoupper($comp->resServ['download']) . '";' . PHP_EOL;
             $file .= "\n/*\n*\n* Services\n*\n*/\n";
             $file .= '// Use the $meet["services"] array with the value as the title (as it will appear to the user)' . PHP_EOL;
             $file .= "// and the key as the suffix of the file. I.e: yymmdd[SUFFIX].htm\n";
             $file .= '// Eg: $meet["services"]["lastheat"] = "Last Heat";' . PHP_EOL;
             foreach ($comp->resServ['services'] as $k => $service) {
                 if ($service == 1) {
                     if (strlen($k) < 7) {
                         $tab = "\t\t";
                     } else {
                         $tab = "\t";
                     }
                     $file .= '$meet["services"]["' . $k . '"]' . $tab . '= "' . $comp->options['res-services'][$k]['title'] . '";' . PHP_EOL;
                 }
             }
             $file .= "\n/*\n*\n* Meet Sessions and Events\n*\n*/\n";
             $file .= '// For each of the sessions, add events to the $meet["session"]["X"]["events"] array, where X is the session number,' . PHP_EOL;
             $file .= "// the key is the initial for the event code and the value is the event title.\n";
             $file .= '// Eg: $meet["session"]["1"]["events"]["F001"]["title" = "Girls 9/O 50m Freestyle";' . PHP_EOL;
             foreach ($comp->meet['S'] as $s => $session) {
                 $file .= "\n// Session " . $s . PHP_EOL;
                 $file .= "// Date\n";
                 $file .= '$meet["session"][' . $s . ']["date"]' . "\t\t\t\t\t\t" . '= ' . strtotime(str_replace('/', '-', $session['date'])) . ';' . PHP_EOL;
                 $file .= "// Start Time\n";
                 $file .= '$meet["session"][' . $s . ']["times"]["start"]' . "\t\t\t" . '= ' . strtotime($session['t']['start']) . ';' . PHP_EOL;
                 $file .= "// Events\n";
                 foreach ($session['E'] as $e => $event) {
                     if ($comp->getEvent($s, $e) !== false) {
                         $event = $comp->getEvent($s, $e);
                         $title = $comp->eventTitle($event, false);
                         if ($event['r'] == 't') {
                             $event['round'] = 'f';
                             $event['r'] = 'h';
                         } else {
                             $event['round'] = $event['r'];
                         }
                         $file .= '$meet["session"][' . $s . ']["events"]["' . strtoupper($event['round']) . str_pad($event['num'], 3, '0', STR_PAD_LEFT) . '"]["title"]' . "\t" . '= "' . $title . '";' . PHP_EOL;
                         $file .= '$meet["session"][' . $s . ']["events"]["' . strtoupper($event['round']) . str_pad($event['num'], 3, '0', STR_PAD_LEFT) . '"]["round"]' . "\t" . '= "' . $comp->options['rounds'][$event['r']] . '";' . PHP_EOL;
                         $file .= '$meet["session"][' . $s . ']["events"]["' . strtoupper($event['round']) . str_pad($event['num'], 3, '0', STR_PAD_LEFT) . '"]["r"]' . "\t\t" . '= "' . $event['r'] . '";' . PHP_EOL;
                         $file .= '$meet["session"][' . $s . ']["events"]["' . strtoupper($event['round']) . str_pad($event['num'], 3, '0', STR_PAD_LEFT) . '"]["s"]' . "\t\t" . '= "' . $event['s'] . '";' . PHP_EOL;
                         $file .= '$meet["session"][' . $s . ']["events"]["' . strtoupper($event['round']) . str_pad($event['num'], 3, '0', STR_PAD_LEFT) . '"]["d"]' . "\t\t" . '= "' . $event['d'] . '";' . PHP_EOL;
                         $file .= '$meet["session"][' . $s . ']["events"]["' . strtoupper($event['round']) . str_pad($event['num'], 3, '0', STR_PAD_LEFT) . '"]["g"]' . "\t\t" . '= "' . $event['g'] . '";' . PHP_EOL;
                     }
                 }
             }
             $file .= "?>\n";
             fwrite($meetFile, $file);
             fclose($meetFile);
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }